本文整理汇总了PHP中Connect::PDOInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Connect::PDOInstance方法的具体用法?PHP Connect::PDOInstance怎么用?PHP Connect::PDOInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connect
的用法示例。
在下文中一共展示了Connect::PDOInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connecting
public function connecting()
{
$now = new DateTime();
$mins = $now->getOffset() / 60;
$sgn = $mins < 0 ? -1 : 1;
$mins = abs($mins);
$hrs = floor($mins / 60);
$mins -= $hrs * 60;
$offset = sprintf('%+d:%02d', $hrs * $sgn, $mins);
// @formatter:off
$this->dsn = $this->parametro['MotorBD'] . ":host=" . $this->parametro['HostBD'] . ";dbname=" . $this->parametro['NameBD'];
// @formatter:on
if (!self::$PDOInstance) {
try {
self::$PDOInstance = new PDO($this->dsn, $this->parametro['UserBD'], $this->parametro['PassBD']);
// self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$PDOInstance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
self::$PDOInstance->setAttribute(PDO::ATTR_PERSISTENT, false);
self::$PDOInstance->exec("SET time_zone = '{$offset}';");
} catch (PDOException $e) {
header('HTTP/1.0 500 Internal Server Error');
// $this->logs->error("Error al conectar: ", $e->getMessage());
echo "Error al conectar: " . $e->getMessage() . "<br/>";
exit;
}
}
}
示例2: connecting
public function connecting()
{
if (isset($this->parametro['MethodConn'])) {
switch ($this->parametro['MethodConn']) {
case 'unix_socket':
$this->methodconnect = 'unix_socket';
break;
case 'tcp':
$this->methodconnect = 'tcp';
break;
default:
$this->methodconnect = 'tcp';
break;
}
} else {
$this->methodconnect = 'tcp';
}
if ($this->methodconnect === 'unix_socket') {
$this->dsn = $this->parametro['MotorBD'] . ":unix_socket=" . $this->parametro['HostBD'];
$this->dsn .= ";dbname=" . $this->parametro['NameBD'];
} else {
$this->dsn = $this->parametro['MotorBD'] . ":host=" . $this->parametro['HostBD'];
$this->dsn .= ";dbname=" . $this->parametro['NameBD'];
}
if (!self::$PDOInstance) {
try {
self::$PDOInstance = new PDO($this->dsn, $this->parametro['UserBD'], $this->parametro['PassBD']);
self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$PDOInstance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
self::$PDOInstance->setAttribute(PDO::ATTR_PERSISTENT, false);
} catch (PDOException $e) {
$this->logs->error("Error al conectar: ", $e->getMessage());
die("Error al conectar: " . $e->getMessage() . "<br/>");
}
}
}