本文整理匯總了PHP中Conexao::pdo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Conexao::pdo方法的具體用法?PHP Conexao::pdo怎麽用?PHP Conexao::pdo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Conexao
的用法示例。
在下文中一共展示了Conexao::pdo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getInstance
public static function getInstance()
{
if (!isset(self::$pdo)) {
// try {
// $opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8', PDO::ATTR_PERSISTENT => TRUE);
// self::$pdo = new PDO("mysql:host=" . HOST . "; dbname=" . DBNAME . "; charset=" . CHARSET . ";", USER, PASSWORD, $opcoes);
// self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// self::$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
// } catch (PDOException $e) {
// throw new PDODBException($e);
// }
$opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8', PDO::ATTR_PERSISTENT => TRUE, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => 1);
$limit = 10;
$counter = 0;
while (true) {
try {
self::$pdo = new PDO('mysql:host=' . HOST . ';dbname=' . DBNAME, USER, PASSWORD, $opcoes);
self::$pdo->exec("SET CHARACTER SET utf8");
self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
self::$pdo->setAttribute(PDO::ATTR_PERSISTENT, true);
self::$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
break;
} catch (PDOException $e) {
$db = null;
$counter++;
if ($counter == $limit) {
throw new PDODBException($e);
}
}
}
}
return self::$pdo;
}
示例2: getInstance
public static function getInstance() {
if (!isset(self::$pdo)) {
try {
$opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8', PDO::ATTR_PERSISTENT => TRUE);
self::$pdo = new PDO("mysql:host=" . HOST . "; dbname=" . DBNAME . "; charset=" . CHARSET . ";", USER, PASSWORD, $opcoes);
self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
print "Erro: " . $e->getMessage();
}
}
return self::$pdo;
}
示例3: getInstance
public static function getInstance()
{
if (!isset(self::$pdo)) {
$opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8', PDO::ATTR_PERSISTENT => TRUE);
$limit = 10;
$counter = 0;
while (true) {
try {
self::$pdo = new PDO('mysql:host=' . HOST . ';dbname=' . DBNAME, USER, PASSWORD, $opcoes);
self::$pdo->exec("SET CHARACTER SET utf8");
self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
self::$pdo->setAttribute(PDO::ATTR_PERSISTENT, true);
break;
} catch (PDOException $e) {
$db = null;
$counter++;
if ($counter == $limit) {
throw new PDOException($e);
}
}
}
}
return self::$pdo;
}