Example #1
0
 public static function setPersonId($userName, $personId)
 {
     $queryString = "UPDATE users SET PersonId=:personId WHERE UserName=:userName";
     $con = Database::pdo();
     $stmt = $con->prepare($queryString);
     $stmt->execute([':userName' => $userName, ':personId' => $personId]);
 }
Example #2
0
 public static function update($id, $firstName, $lastName, $birthDate)
 {
     $queryString = "\n          UPDATE person\n          SET FirstName=:firstName, LastName=:lastName, BirthDate=:birthDate\n          WHERE Id=:id";
     $con = Database::pdo();
     $stmt = $con->prepare($queryString);
     $stmt->execute([':id' => $id, ':firstName' => $firstName, ':lastName' => $lastName, ':birthDate' => $birthDate]);
 }
Example #3
0
 public static function get($senderId, $receiverId)
 {
     $con = Database::pdo();
     $stmt = $con->prepare("SELECT * FROM messages\n          WHERE SenderId=:senderId AND ReceiverId=:receiverId");
     $stmt->execute([':senderId' => $senderId, ':receiverId' => $receiverId]);
     return $stmt->fetchAll();
 }
Example #4
0
 public static function pdo()
 {
     if (!isset(self::$pdo)) {
         self::$pdo = new PDO('mysql:host=localhost;dbname=itstep_db', 'itstep', '123123');
         self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
     }
     return self::$pdo;
 }
Example #5
0
 public static function connect($db = 'test', $pass = '', $user = '******', $host = 'localhost', $type = 'mysql')
 {
     try {
         self::$pdo = new PDO("{$type}:host={$host};dbname={$db}", $user, $pass);
         self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         echo 'ERROR: ' . $e->getMessage();
     }
 }
Example #6
0
 /**
  * @return PDO $pdo
  */
 public static function getPDO()
 {
     if (self::$pdo == null) {
         self::$pdo = new PDO(Config::$databaseDsn, Config::$databaseUsername, Config::$databasePassword);
         return self::$pdo;
     } else {
         return self::$pdo;
     }
 }
 public function __construct($host, $user, $password, $dbname)
 {
     try {
         self::$pdo = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $user, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ]);
         self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         var_dump($e->getMessage());
     }
     return self::$pdo;
 }
Example #8
0
 private function __construct()
 {
     $dsn = "mysql:host={$this->host};charset=utf8";
     $opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
     try {
         $pdo = new PDO($dsn, $this->username, $this->password, $opt);
         self::$pdo = $pdo;
     } catch (PDOException $e) {
         die('connection failed ' . $e->getMessage());
     }
 }
Example #9
0
 private static function connect()
 {
     try {
         self::$pdo = new PDO(Config::get('database/sgbd') . ':host=' . Config::get('database/host') . ';dbname=' . Config::get('database/dbname'), Config::get('database/user'), Config::get('database/pass'));
         self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         return self::$pdo;
     } catch (PDOException $e) {
         CodeFail((int) $e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
         die;
     }
 }
Example #10
0
 public static function getDB()
 {
     if (!isset(self::$pdo)) {
         try {
             self::$pdo = new PDO(self::$dsn, self::$username, self::$password);
         } catch (PDOException $e) {
             die($e->getMessage());
         }
     }
     return self::$pdo;
 }
Example #11
0
 /**
  *	Connect
  * 
  *	@return void
  */
 private function connect()
 {
     // Load config from /app/config/database.php
     $cfg = (include dirname(__FILE__) . '/' . $this->cfg_file);
     $this->cfg = $cfg + $this->cfg;
     // Check for the PDO driver
     if (class_exists('PDO') === false) {
         exit('The PDO driver was not found. Enable the PDO driver in php.ini.');
     }
     try {
         self::$pdo = new PDO($cfg['driver'] . ':host=' . $cfg['hostname'] . ';dbname=' . $cfg['database'], $cfg['username'], $cfg['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $cfg['charset'] . ' COLLATE ' . $cfg['collation']));
         $this->prefix = $cfg['prefix'];
     } catch (PDOException $e) {
         exit('Unable to connect to the database.');
     }
 }
Example #12
0
 /**
  * Execute a query and return the result set as an array of rows
  *
  * @param string $query
  * The query to execute
  *
  * @param array $parameters
  * The parameters, as an associative array of parameter names=>values
  *
  * @return array|bool
  * The array of rows returned or false if the query fails
  */
 public static function query($query, $parameters = null)
 {
     // prepare the statement
     $stmt = Database::pdo()->prepare($query);
     // bind the parameters
     if ($parameters) {
         foreach ($parameters as $key => $value) {
             $stmt->bindValue($key, $value);
         }
     }
     $success = $stmt->execute();
     if (!$success) {
         return false;
     }
     // get the result set
     return $stmt->fetchAll(PDO::FETCH_ASSOC);
 }
Example #13
0
 public static function getDB()
 {
     if (!isset(self::$pdo)) {
         try {
             //self::$pdo = new PDO("sqlsrv:server={self::$host};Database={self::$db}");
             self::$pdo = new PDO(self::$dsn);
             if (self::$debug) {
                 self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             }
         } catch (PDOException $e) {
             die(self::$debug ? $e->getMessage() : '');
             //$error_message = $e->getMessage();
             //include('database_error.php');
             //exit();
         }
     }
     return self::$pdo;
 }
Example #14
0
 public static function connect()
 {
     self::database_config_attributes();
     if (!isset($pdo)) {
         try {
             self::$pdo = new PDO("mysql:" . "host=" . self::$host . ";" . "dbname=" . self::$dbname, self::$username, self::$password);
         } catch (PDOException $e) {
             if ($e->getCode() == 2002) {
                 echo "This Localhost no exist";
             } elseif ($e->getCode() == 1049) {
                 echo "This Database no exist";
             } elseif ($e->getCode() == 1044) {
                 echo "This Username no exist";
             } elseif ($e->getCode() == 1045) {
                 echo "Database Password are incorrect";
             }
         }
     }
     return self::$pdo;
 }
Example #15
0
 public static function connect()
 {
     self::database_config_attributes();
     if (!isset($pdo)) {
         try {
             self::$pdo = new PDO("mysql:" . "host=" . self::$host . ";" . "dbname=" . self::$dbname, self::$username, self::$password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
         } catch (PDOException $e) {
             if ($e->getCode() == 2002) {
                 echo "<b>Database configuration Error:</b> This Localhost not exist in this server";
                 exit;
             } elseif ($e->getCode() == 1049) {
                 echo "<b>Database configuration Error:</b> This Database not exist in this server";
                 exit;
             } elseif ($e->getCode() == 1044) {
                 echo "<b>Database configuration Error:</b> Database username not exist in this server";
                 exit;
             } elseif ($e->getCode() == 1045) {
                 echo "<b>Database configuration Error:</b> Database Password are incorrect";
                 exit;
             }
         }
     }
     return self::$pdo;
 }
Example #16
0
 function __destruct()
 {
     self::$pdo = null;
 }
 function _destructor()
 {
     self::$pdo = null;
 }
Example #18
0
 /**
  * 查询所有字段
  * @param $table
  * @return array
  */
 static function fields($table)
 {
     $pdo = Database::pdo();
     $result = $pdo->query("SHOW FULL COLUMNS FROM  {$table}");
     $fields = array();
     while ($row = $result->fetch()) {
         print_r($row);
         $fields[] = $row[0];
     }
     return $fields;
 }
 /**
  * Initialise la classe en vue de son utilisation
  * Crée un objet PDO à usage interne pour communiquer avec la base de donnée.
  * Toute exécution après la première n'a aucun effet.
  */
 static function Init()
 {
     if (empty(self::$pdo)) {
         self::$pdo = new PDO('mysql:dbname=' . DB_NAME . ';host=' . DB_HOST . ';charset=UTF8', DB_USER, DB_PWD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);
     }
 }
Example #20
0
 /**
  * Disconnect from the current MySQL server.  Function is automatically called at the end of page execution.
  *
  * @return boolean True on success or False on failure
  * @static
  */
 public static function Disconnect()
 {
     self::$pdo = null;
 }
Example #21
0
 protected final function __clone()
 {
     self::$pdo = null;
 }
Example #22
0
 /**
  * 查询记录数
  * @return int
  */
 static function count($query = null)
 {
     $pdo = Database::pdo();
     $params = $query->getParameters();
     $ops = $query->getOperators();
     $count = 0;
     $sql = "select count(*) from meta_table";
     Sql::splice($sql, MetaTableDao::$fields, $params, $ops);
     $stmt = $pdo->prepare($sql);
     Sql::params($stmt, $params);
     $stmt->execute();
     $row = $stmt->fetch(PDO::FETCH_NUM);
     $count = $row[0];
     $stmt->closeCursor();
     return $count;
 }
Example #23
0
 function __construct()
 {
     $config = parse_ini_file(ROOT_DIR . '../config.ini');
     parent::__construct('mysql:host=localhost;dbname=' . $config['dbname'], $config['username'], $config['password']);
     self::$pdo = $this;
 }