Advertisement
Guest User

Untitled

a guest
Aug 6th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <?php
  2. require_once('confic.inc.php');
  3. class db {
  4. static public $host;
  5. static public $user = '';
  6. static public $password = '';
  7. static public $database = '';
  8. private static $db;
  9.  
  10. function __construct() {
  11. global $dbhost;
  12. global $dbuser;
  13. global $dbpass;
  14. global $dbase;
  15.  
  16. self::$host = $dbhost;
  17. self::$user = $dbuser;
  18. self::$password = $dbpass;
  19. self::$database = $dbase;
  20. }
  21.  
  22. static public function dbstart() {
  23. if(!self::$db) {
  24. try {
  25. self::$db = new PDO ('
  26. mysql:host='.self::$host.';
  27. dbname='.self::$database.';
  28. port=3306',
  29. self::$user,
  30. self::$password,
  31. array(
  32. PDO::ATTR_PERSISTENT => ture,
  33. PDO::MYSQL_ATTR_INIT_COMMAND = > 'SET NAMES utf8 COLLATE utf8_general_ci',
  34. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
  35. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  36. )
  37. );
  38. } catch(PDOException $e) {
  39. $errorarray = $stmt->errorInfo();
  40. print_r($errorarray);
  41. }
  42. }
  43. return self::$db;
  44. }
  45.  
  46. function dbQuery($sql = '', $params = array()) {
  47. try {
  48. $stmt = self::dbstart()->prepare($sql);
  49. if (is_array($params) == true) {
  50. $id = 1;
  51. foreach ($params AS $param) {
  52. $stmt->bindValue($id, $param);
  53. $id++;
  54. }
  55. }
  56. $stmt->execute();
  57. $this->num_rows = $stmt->rowCount();
  58. return $stmt;
  59. } catch (PDOException $e) {
  60. $errorarray = $stmt->errorInfo();
  61. print_r($errorarray);
  62. }
  63. }
  64.  
  65. function fetch() {
  66. return self::fetch();
  67. }
  68.  
  69. function numRows() {
  70. return $this->num_rows;
  71. }
  72. }
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement