Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('confic.inc.php');
- class db {
- static public $host;
- static public $user = '';
- static public $password = '';
- static public $database = '';
- private static $db;
- function __construct() {
- global $dbhost;
- global $dbuser;
- global $dbpass;
- global $dbase;
- self::$host = $dbhost;
- self::$user = $dbuser;
- self::$password = $dbpass;
- self::$database = $dbase;
- }
- static public function dbstart() {
- if(!self::$db) {
- try {
- self::$db = new PDO ('
- mysql:host='.self::$host.';
- dbname='.self::$database.';
- port=3306',
- self::$user,
- self::$password,
- array(
- PDO::ATTR_PERSISTENT => ture,
- PDO::MYSQL_ATTR_INIT_COMMAND = > 'SET NAMES utf8 COLLATE utf8_general_ci',
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- )
- );
- } catch(PDOException $e) {
- $errorarray = $stmt->errorInfo();
- print_r($errorarray);
- }
- }
- return self::$db;
- }
- function dbQuery($sql = '', $params = array()) {
- try {
- $stmt = self::dbstart()->prepare($sql);
- if (is_array($params) == true) {
- $id = 1;
- foreach ($params AS $param) {
- $stmt->bindValue($id, $param);
- $id++;
- }
- }
- $stmt->execute();
- $this->num_rows = $stmt->rowCount();
- return $stmt;
- } catch (PDOException $e) {
- $errorarray = $stmt->errorInfo();
- print_r($errorarray);
- }
- }
- function fetch() {
- return self::fetch();
- }
- function numRows() {
- return $this->num_rows;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement