本文整理汇总了PHP中PDO::errorinfo方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::errorinfo方法的具体用法?PHP PDO::errorinfo怎么用?PHP PDO::errorinfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::errorinfo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromDbTab
/**
* Tableau rempli à partir de la base bibliothèque
**/
function fromDbTab()
{
//Récupère les données de la BD
try {
$conn = new PDO('mysql:dbname=bibliotheque;host=127.0.0.1;charset=utf8', 'root', '');
} catch (PDOException $e) {
echo 'Connexion impossible : ' . $e->getMessage();
return;
}
if (!($stmt = $conn->query('SELECT * FROM auteur'))) {
die(var_export($conn->errorinfo(), TRUE));
}
//Lance la création du tableau
$table = new AutoTab\Table('Liste des auteurs');
$table->addHeadersStr(array('Id', 'Nom', 'Prénom', 'Année de naissance'));
foreach ($stmt as $data) {
$table->addRowStr(array($data['id_auteur'], $data['nom'], $data['prenom'], $data['date_naissance']));
}
$table->render();
}
示例2: die
<tr><td><label for="date_sortie"> Date de sortie </label></td><td><input type="text" name="date_sortie" id="date_sortie" value="<?php
echo $ouvrages_items['date_de_sortie'];
?>
"tabindex ="17"/></td></tr>
<tr><td><label for="nombre_exemple"> Nombre d'exemplaire </label></td><td><input type="text" name="nombre_exemple" id="nombre_exemple" value="<?php
echo $ouvrages_items['nombre_exemplaire'];
?>
"tabindex ="20"/></td></tr>
<tr><td><label for="num_rang"> N° de rangé </label></td><td><input type="text" name="num_rang" id="num_rang" value="<?php
echo $ouvrages_items['N_range'];
?>
"tabindex ="25"/></td></tr>
<tr><td><label for="theme1">Théme</label></td><td>
<select name="theme1" id="theme1" tabindex ="30">
<?php
$themec = $bdd->prepare('SELECT * FROM categorie WHERE ID_theme =?') or die(print_r($bdd->errorinfo()));
$themec->execute(array($ouvrages_items['ID_theme']));
$theme_courant = $themec->fetch();
?>
<optgroup label ="Theme Courant"><option value="<?php
echo $theme_courant['theme'];
?>
"><?php
echo $theme_courant['theme'];
$themec->closeCursor();
?>
</option></optgroup>
<optgroup label ="Nouveau Theme">
<?php
$theme = $bdd->query('SELECT * FROM categorie ');
while ($theme_items = $theme->fetch()) {
示例3: query
/**
* Query the database
*
* @param integer $type
* @param string $sql
* @param mixed $as_object
*
* @return mixed
*
* @throws \Database_Exception
*/
public function query($type, $sql, $as_object)
{
// Make sure the database is connected
$this->_connection or $this->connect();
if (!empty($this->_config['profiling'])) {
// Get the paths defined in config
$paths = \Config::get('profiling_paths');
// Storage for the trace information
$stacktrace = array();
// Get the execution trace of this query
$include = false;
foreach (debug_backtrace() as $index => $page) {
// Skip first entry and entries without a filename
if ($index > 0 and empty($page['file']) === false) {
// Checks to see what paths you want backtrace
foreach ($paths as $index => $path) {
if (strpos($page['file'], $path) !== false) {
$include = true;
break;
}
}
// Only log if no paths we defined, or we have a path match
if ($include or empty($paths)) {
$stacktrace[] = array('file' => \Fuel::clean_path($page['file']), 'line' => $page['line']);
}
}
}
$benchmark = \Profiler::start($this->_instance, $sql, $stacktrace);
}
// run the query. if the connection is lost, try 3 times to reconnect
$attempts = 3;
do {
try {
// try to run the query
$result = $this->_connection->query($sql);
break;
} catch (\Exception $e) {
// if failed and we have attempts left
if ($attempts > 0) {
// try reconnecting if it was a MySQL disconnected error
if (strpos($e->getMessage(), '2006 MySQL') !== false) {
$this->disconnect();
$this->connect();
} else {
// other database error, cleanup the profiler
isset($benchmark) and \Profiler::delete($benchmark);
// and convert the exception in a database exception
if (!is_numeric($error_code = $e->getCode())) {
if ($this->_connection) {
$error_code = $this->_connection->errorinfo();
$error_code = $error_code[1];
} else {
$error_code = 0;
}
}
throw new \Database_Exception($e->getMessage() . ' with query: "' . $sql . '"', $error_code, $e);
}
} else {
// and convert the exception in a database exception
if (!is_numeric($error_code = $e->getCode())) {
if ($this->_connection) {
$error_code = $this->_connection->errorinfo();
$error_code = $error_code[1];
} else {
$error_code = 0;
}
}
throw new \Database_Exception($e->getMessage() . ' with query: "' . $sql . '"', $error_code, $e);
}
}
} while ($attempts-- > 0);
if (isset($benchmark)) {
\Profiler::stop($benchmark);
}
// Set the last query
$this->last_query = $sql;
if ($type === \DB::SELECT) {
// Convert the result into an array, as PDOStatement::rowCount is not reliable
if ($as_object === false) {
$result = $result->fetchAll(\PDO::FETCH_ASSOC);
} elseif (is_string($as_object)) {
$result = $result->fetchAll(\PDO::FETCH_CLASS, $as_object);
} else {
$result = $result->fetchAll(\PDO::FETCH_CLASS, 'stdClass');
}
// Return an iterator of results
return new \Database_Result_Cached($result, $sql, $as_object);
} elseif ($type === \DB::INSERT) {
// Return a list of insert id and rows created
//.........这里部分代码省略.........
示例4: PDO
<?php
#date_default_timezone_set('RPC');
$dsn = "mysql:host=localhost;dbname=zero_php";
$pdo = new PDO($dsn, "root", "root");
#$result = $pdo->exec($sql); // 用于insert update delete
$sql = "select * from zp_user order by uuid desc";
$result = $pdo->query($sql);
// $userList = NULL;
if (!$result) {
$userList = $pdo->errorinfo();
}
$userList = $pdo->query($sql);
// 用于select
include_once zeroPath('/pages/index.php');
exit;
foreach ($userList as $user) {
// var_dump($user);
echo "username============>" . $user['user_name'] . "<br>";
echo "password============>" . $user['password'] . "<br>";
if ($user['sex'] == 0) {
echo "sex============>女<br>";
} else {
echo "sex============>男<br>";
}
echo "age============>" . $user['age'] . "<br>";
echo "avatar============>" . $user['avatar'] . "<br>";
echo "login_time============>" . $user['time'] . "<br>";
echo "last_time============>" . $user['last_time'] . "<br>";
echo "login_ip============>" . $user['login_ip'] . "<br>";
echo "-------------------------------------------------------------------------------<br>";
示例5: strtoupper
} else {
$action = strtoupper($_GET['action']);
}
switch ($action) {
default:
case 'LIST':
// retrieve contacts and display as table (list)
// build query
$query = 'SELECT id, firstname, lastname, email FROM contacts';
// send query to server
$results = $dbh->query($query);
// check server result
if ($results === false) {
// query error
echo '<p>Query error. No soup for you! *snap*</p>';
echo '<p>Error info: ' . $dbh->errorinfo()[2] . '</p>';
break;
// terminate case
}
// process results if applicable
$rowHTML = '';
$rowCount = 0;
// loop through results
while ($row = $results->fetch(PDO::FETCH_ASSOC)) {
$rowCount++;
$rowHTML .= '<tr>' . '<td>' . $row['id'] . '</td>' . '<td>' . $row['firstname'] . '</td>' . '<td>' . $row['lastname'] . '</td>' . '<td>' . $row['email'] . '</td>' . '</tr>';
}
// while
if ($rowCount > 0) {
// build table
echo '<table><tbody>' . $rowHTML . '</tbody></table>';