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; } } }
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/>"); } } }