本文整理汇总了PHP中PDO::errorInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::errorInfo方法的具体用法?PHP PDO::errorInfo怎么用?PHP PDO::errorInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::errorInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* @param PDO $link
* @param string $user
* @param string $field1
* @param string $field2
* @param string $lang
* @param string $group
* @param string $id1
* @param string $id2
* @param string $word
* @param int $type
*/
function update($link, $user, $field1, $field2, $lang, $group, $id1, $id2, $word, $type)
{
$sql = "SELECT associd FROM `associations` WHERE id1 = :id1 AND id2 = :id2 AND word = :word AND user = :user AND assigned_group = :group AND lang = :lang AND type = :type";
$stmt = $link->prepare($sql);
$stmt->bindValue(':id1', $id1, PDO::PARAM_STR);
$stmt->bindValue(':id2', $id2, PDO::PARAM_STR);
$stmt->bindValue(':word', $word, PDO::PARAM_STR);
$stmt->bindValue(':type', $type, PDO::PARAM_INT);
$stmt->bindValue(':user', $user, PDO::PARAM_STR);
$stmt->bindValue(':group', $group, PDO::PARAM_STR);
$stmt->bindValue(':lang', $lang, PDO::PARAM_STR);
if ($stmt->execute() === false) {
error_log(var_export($link->errorInfo(), true));
die("Error performing database operation.");
}
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$sql = "INSERT INTO `evaluations` ( associd , evaluator , vote , popvote ) values ( :associd , :user , :vote , :popvote )";
$stmt = $link->prepare($sql);
$stmt->bindValue(':associd', $row['associd'], PDO::PARAM_STR);
$stmt->bindValue(':user', $_SESSION['user_array']['user'], PDO::PARAM_STR);
$stmt->bindValue(':vote', $field1 === 'upvotes' ? 2 : ($field1 === 'neutralvotes' ? 1 : 0), PDO::PARAM_INT);
$stmt->bindValue(':popvote', $field2 === 'popupvotes' ? 2 : ($field2 === 'popneutralvotes' ? 1 : 0), PDO::PARAM_INT);
if ($stmt->execute() === false) {
error_log(var_export($link->errorInfo(), true));
die("Error performing database operation.");
}
}
}
示例2: do_query
/**
* Prepare and execute a query.
*
* If the query fails, output a diagnostic message
* @param string $query
* Query to run
* @return bool
*/
public function do_query($query)
{
// echo "do_query($query)\n";
// $stmt = $this->pdo->query( $query, PDO::FETCH_ASSOC );
// echo "PDO returned";
// var_dump($stmt);
$string = preg_replace("/^#[^\n]*\$/m", "\n", $query);
$string = preg_replace("/^(--[^-]).*/m", "\n", $string);
$queries = preg_split('/;\\s*$/m', $string);
foreach ($queries as $query) {
$query = trim($query);
if (!empty($query)) {
$result = $this->pdo->query($query);
if ($this->pdo->errorCode() == 0) {
continue;
} else {
var_dump($result);
var_dump($this->pdo->errorInfo());
// die( "Cannot execute $query: " . $this->pdo->errorInfo() );
}
}
}
/*******
* if ( $this->pdo->errorCode() == 0 ) {
* //echo "returning the PDOStmt\n";
* return $stmt;
* }
*
* // operation failed, so output description of where and why
* $errorInfo = $this->pdo->errorInfo();
* echo "Oops, can't do query:\n {$query}\n in "
* . basename( __FILE__) . " line " . __LINE__.":\n "
* . $errorInfo[0] . ": " . $errorInfo[2] . "\n Call stack:\n";
* $backtrace = debug_backtrace();
* $dir_name = dirname( __FILE__ );
* $cwd_len = strlen( $dir_name ) + 1;
* foreach ($backtrace as $frame ) {
* echo " ";
* if ( array_key_exists( 'class', $frame ) ) {
* echo " class {$frame['class']}";
* if ( array_key_exists( 'function', $frame ) ) {
* echo " method {$frame['function']}";
* }
* }
* else {
* if ( array_key_exists( 'function', $frame ) ) {
* echo " function {$frame['function']}";
* }
* }
* if ( array_key_exists( 'file', $frame ) ) {
* echo " file ". substr( $frame['file'], $cwd_len );
* }
* if ( array_key_exists( 'line', $frame ) ) {
* echo " line {$frame['line']}";
* }
* echo "\n";
* }
******/
return TRUE;
}
示例3: query
/**
* {@inheritdoc}
*/
public function query($query, $resultsetType = Resultset::TYPE_ARRAY)
{
try {
//$query = "select * from product";
$stmt = $this->resource->prepare($query);
if ($stmt === false) {
$error = $this->resource->errorInfo();
throw new Exception\InvalidArgumentException($error[2]);
}
if (!$stmt->execute()) {
throw new Exception\InvalidArgumentException('Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')');
}
$results = new Resultset($resultsetType);
if ($stmt->columnCount() > 0) {
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$results->append($row);
}
}
$stmt->closeCursor();
} catch (Exception\InvalidArgumentException $e) {
throw $e;
} catch (\Exception $e) {
$eclass = get_class($e);
$msg = "GenericPdo '{$eclass}' : {$e->getMessage()} [{$query}]";
throw new Exception\InvalidArgumentException($msg);
}
return $results;
}
示例4: _error_handler
private function _error_handler($errtext, $errline)
{
$err = sprintf('%s on line %d.', $errtext, $errline);
if (defined('DEBUG') && DEBUG) {
$err .= sprintf(PHP_EOL . "Description: %s", print_r($this->con->errorInfo(), true));
}
throw new RuntimeException($err);
}
示例5: get_error_message
/**
* Get the latest error message from the DB driver
*
* @return string
*/
public function get_error_message()
{
$error = $this->dbh->errorInfo();
if (isset($error[2])) {
return $error[2];
}
return '';
}
示例6: initDb
private function initDb()
{
$this->pdo = new \PDO($this->dns, $this->user, $this->pass, $this->options);
if ($this->pdo == false) {
throw new \Exception(var_export($this->pdo->errorInfo(), true));
}
$this->optionsChanged = false;
}
示例7: DoLastError
public function DoLastError()
{
if ($this->connection) {
$pdoErrorInfo = $this->connection->errorInfo();
return $pdoErrorInfo[2];
} else {
return $this->connectionError;
}
}
示例8: loadFixture
/**
* @param string $fixture
*
* @throws \InvalidArgumentException
*/
public function loadFixture($fixture)
{
if (!is_file(__DIR__ . "/fixtures/{$fixture}.sql")) {
throw new \InvalidArgumentException("The asked fixture file {$fixture}.sql does not exists");
}
$success = $this->getConnection()->exec(file_get_contents(__DIR__ . "/fixtures/{$fixture}.sql"));
if ($success === false) {
$this->fail("Error with {$fixture} fixtures : {$this->connection->errorInfo()[2]}");
}
}
示例9: error
/**
* Generate PDO error
*
* @param string $sql
* @param \PDOStatement $statement
* @return \PDOException
*/
protected function error($sql, \PDOStatement $statement = null)
{
$error = $this->pdo->errorInfo();
if (!$error[1] and $statement) {
$error = $statement->errorInfo();
$statement->closeCursor();
unset($statement);
}
$code = is_int($error[0]) ? $error[0] : null;
return new \PDOException('[' . $error[0] . '] ' . $error[2] . ', in query (' . $sql . ')', $code);
}
示例10: getMembers
/**
* @return Member[]
*/
public function getMembers()
{
$statement = $this->pdo->query('SELECT * FROM members');
if (false === $statement) {
throw new \PDOException(join("\n", $this->pdo->errorInfo()), $this->pdo->errorCode());
}
$members = [];
while ($row = $statement->fetch(\PDO::FETCH_OBJ)) {
$members[] = $this->rowToMember($row);
}
return $members;
}
示例11: run
public function run(SqlFile $file)
{
$statement = $this->pdo->prepare($file->getContents());
try {
$result = $statement->execute();
if ($result === false) {
throw new \Exception("Query Returned " . var_export($this->pdo->errorInfo(), true));
}
} catch (\Exception $e) {
throw new MigrationException("Running SQL File " . $file->getFile()->getPathname() . " failed.", $e);
} finally {
$statement->closeCursor();
}
}
示例12: executePdoQuery
/**
* Internal function to execute PDO queries when the
* query option is set to a PDO object
* @param string $query The SQL query to execute
* @param array $parameters Parameters to bind to the query
* @return array
*/
function executePdoQuery($query, $parameters)
{
$stmt = $this->dbh->prepare($query);
if (!$stmt) {
echo "Error in preparing query: " . $this->dbh->errorCode() . " " . htmlentities(print_r($this->dbh->errorInfo(), true)) . " " . htmlentities($query);
exit;
}
$res = $stmt->execute($parameters);
if (!$res) {
echo "Error in executing query: " . $stmt->errorCode() . " " . htmlentities(print_r($stmt->errorInfo(), true)) . " " . htmlentities($query);
exit;
}
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
示例13: open_db
function open_db()
{
// Try to open the db itself. If that fails, try to create it.
$dbFile = SUPPORT_DIR . DIRECTORY_SEPARATOR . "jobs.sqlite";
$pdo = new PDO("sqlite:{$dbFile}", null, null);
if (!$pdo) {
throw new DbException($pdo->errorInfo(), "Error opening (or creating) " . $dbFile);
}
$stmt = 'CREATE TABLE IF NOT EXISTS ' . TABLE_NAME . ' (jobId TEXT, username TEXT, filename TEXT, when_added INTEGER, PRIMARY KEY (jobId))';
// SQLite doesn't have a specific date type. We're using integer seconds (Unix time)
if ($pdo->exec($stmt) === false) {
throw new DbException($pdo->errorInfo(), 'Error creating ' . TABLE_NAME . ' table');
}
return $pdo;
}
示例14: query
/**
* 执行一条sql语句
* 返回数组或者bool
*
* @param $sql
* @return array|bool
*/
public function query($sql)
{
$dbh = $this->dbh;
$this->_beforeQuery($sql);
$ps = $dbh->query($sql);
$error_info = $this->dbh->errorInfo();
if ($error_info[2] != null) {
throw new Exception("Excute Sql Error: " . $error_info[2]);
}
if (is_bool($ps)) {
return $ps;
}
$obj = $ps->fetchAll(PDO::FETCH_ASSOC);
return $obj;
}
示例15: execute
/**
* @param string $cmd Sql SAFE query to execute.
* @param array $bind Array of parameters to bind.
* @throws \PDOException
* @return \PDOStatement
*/
public function execute($cmd, array $bind = [])
{
if (is_null($this->pdo)) {
$this->openConnection();
}
$statement = $this->pdo->prepare($cmd);
if (!$statement) {
throw MySqlException::create($this->pdo->errorInfo());
}
$result = $statement->execute($bind);
if (!$result) {
throw MySqlException::create($statement->errorInfo());
}
return $statement;
}