Guest User

Untitled

a guest
Dec 27th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public $query;
  2. public $fetchAll;
  3. public $result;
  4. public $response;
  5. protected $config;
  6. protected $driver;
  7. protected $host;
  8. protected $port;
  9. protected $user;
  10. protected $pass;
  11. protected $dbname;
  12. protected $con;
  13.  
  14. public function __construct( $config )
  15. {
  16. try
  17. {
  18. #array com dados do banco
  19. $this->config = $config;
  20. # Recupera os dados de conexao do config
  21. $this->dbname = $this->config['dbname'];
  22. $this->driver = $this->config['driver'];
  23. $this->host = $this->config['host'];
  24. $this->port = $this->config['port'];
  25. $this->user = $this->config['user'];
  26. $this->pass = $this->config['password'];
  27. # instancia e retorna objeto
  28. $this->con = mysql_connect( "$this->host", "$this->user", "$this->pass" );
  29. @mysql_select_db( "$this->dbname" );
  30. if( !$this->con )
  31. {
  32. throw new Exception( "Falha na conexão MySql com o banco [$this->dbname] em " . DATABASEDIR . "database.conf.php" );
  33. }
  34. else
  35. {
  36. return $this->con;
  37. }
  38. }
  39. catch( Exception $e )
  40. {
  41. echo $e->getMessage();
  42. exit;
  43. }
  44. return $this;
  45. }
  46.  
  47. public function query( $query = '' )
  48. {
  49. try
  50. {
  51. if( $query == '' )
  52. {
  53. throw new Exception( 'mysql query: A query deve ser informada como parâmetro do método.' );
  54. }
  55. else
  56. {
  57. $this->query = $query;
  58. $this->result = mysql_query( $this->query );
  59. if(!$this->result)
  60. {
  61. $this->response = "Erro " .mysql_errno()." => ". mysql_error();
  62. }
  63. else
  64. {
  65. $this->response = "success";
  66. }
  67. }
  68. }
  69. catch( Exception $e )
  70. {
  71. echo $e->getMessage();
  72. exit;
  73. }
  74. return $this;
  75. }
  76.  
  77. public function fetchAll()
  78. {
  79. $this->fetchAll = "";
  80. while( $row = @mysql_fetch_array( $this->result, MYSQL_ASSOC ) )
  81. {
  82. $this->fetchAll[] = $row;
  83. }
  84. return $this->fetchAll;
  85. }
  86.  
  87. public function rowCount()
  88. {
  89. return @mysql_affected_rows();
  90. }
  91.  
  92. public function limit( $limit, $offset )
  93. {
  94. return "LIMIT " . (int) $limit . "," . (int) $offset;
  95. }
Add Comment
Please, Sign In to add comment