Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. <?php
  2. /* Adapter mysql */
  3. Class mysql
  4. {
  5.  
  6. public $query;
  7. public $fetchAll;
  8. public $result;
  9. public $response;
  10. protected $config;
  11. protected $driver;
  12. protected $host;
  13. protected $port;
  14. protected $user;
  15. protected $pass;
  16. protected $dbname;
  17. protected $con;
  18.  
  19. public function __construct( $config )
  20. {
  21. try
  22. {
  23. #array com dados do banco
  24. $this->config = $config;
  25. # Recupera os dados de conexao do config
  26. $this->dbname = $this->config['dbname'];
  27. $this->driver = $this->config['driver'];
  28. $this->host = $this->config['host'];
  29. $this->port = $this->config['port'];
  30. $this->user = $this->config['user'];
  31. $this->pass = $this->config['password'];
  32. # instancia e retorna objeto
  33. $this->con = @mysql_connect( "$this->host", "$this->user", "$this->pass" );
  34. @mysql_select_db( "$this->dbname" );
  35. if( !$this->con )
  36. {
  37. throw new Exception( "Falha na conex�o MySql com o banco [$this->dbname] em " . DATABASEDIR . "database.conf.php" );
  38. }
  39. else
  40. {
  41. return $this->con;
  42. }
  43. }
  44. catch( Exception $e )
  45. {
  46. echo $e->getMessage();
  47. exit;
  48. }
  49. return $this;
  50. }
  51.  
  52. public function query( $query = '' )
  53. {
  54. try
  55. {
  56. if( $query == '' )
  57. {
  58. throw new Exception( 'mysql query: A query deve ser informada como parâmetro do método.' );
  59. }
  60. else
  61. {
  62. $this->query = $query;
  63. $this->result = @mysql_query( $this->query );
  64. if(!$this->result)
  65. {
  66. $this->response = "Erro " .mysql_errno()." => ". mysql_error();
  67. }
  68. else
  69. {
  70. $this->response = "success";
  71. }
  72. }
  73. }
  74. catch( Exception $e )
  75. {
  76. echo $e->getMessage();
  77. exit;
  78. }
  79. return $this;
  80. }
  81.  
  82. public function fetchAll()
  83. {
  84. $this->fetchAll = "";
  85. while( $row = @mysql_fetch_array( $this->result, MYSQL_ASSOC ) )
  86. {
  87. $this->fetchAll[] = $row;
  88. }
  89. return $this->fetchAll;
  90. }
  91.  
  92. public function rowCount()
  93. {
  94. return @mysql_affected_rows();
  95. }
  96.  
  97. public function limit( $limit, $offset )
  98. {
  99. return "LIMIT " . (int) $limit . "," . (int) $offset;
  100. }
  101. }
  102. /* end file */
  103.  
  104. **database.conf.php**
  105.  
  106. <?php
  107.  
  108. $databases = array(
  109. # MYSQL
  110. 'default' => array
  111. (
  112. 'driver' => 'mysql',
  113. 'host' => 'localhost',
  114. 'port' => 3306,
  115. 'dbname' => 'dbname',
  116. 'user' => 'root',
  117. 'password' => '',
  118. 'emailAdmin' => 'e-mail.com'// email para receber mensagens do chat
  119. )
  120. );
  121.  
  122. <?php
  123.  
  124. Class Conexao extends PDO
  125. {
  126.  
  127. protected $config;
  128. protected $driver;
  129. protected $sgbd;
  130. protected $host;
  131. protected $port;
  132. protected $user;
  133. protected $pass;
  134. protected $dbname;
  135. protected $strcon;
  136. protected $con;
  137.  
  138. public function __construct( $config )
  139. {
  140. try
  141. {
  142. #array com dados do banco
  143. $this->config = $config;
  144. # Recuperando os dados de conexao do driver
  145. $this->dbname = $this->config['dbname'];
  146. $this->driver = $this->config['driver'];
  147. $this->sgbd = $this->config['sgbd'];
  148. $this->host = $this->config['host'];
  149. $this->port = $this->config['port'];
  150. $this->user = $this->config['user'];
  151. $this->pass = $this->config['password'];
  152. $this->strCon = "$this->sgbd:host=$this->host;port=$this->port;";
  153. # instancia e retorna objeto PDO
  154. $this->con = parent :: __construct( "$this->strCon dbname=$this->dbname", $this->user, $this->pass, array( PDO::ATTR_PERSISTENT => true ) );
  155. return $this->con;
  156. }
  157. catch( PDOException $e )
  158. {
  159. echo 'A Conexão falhou: ' . $e->getMessage();
  160. exit;
  161. }
  162. }
  163.  
  164. public function close()
  165. {
  166. unset( $this->con );
  167. unset( $this->dbname );
  168. unset( $this->config );
  169. }
  170. }
  171. /* end file */
  172.  
  173. <?php
  174. /* Adapter mysql */
  175. Class mysql
  176. {
  177.  
  178. public $query;
  179. public $fetchAll;
  180. public $result;
  181. public $response;
  182. protected $config;
  183. protected $driver;
  184. protected $host;
  185. protected $port;
  186. protected $user;
  187. protected $pass;
  188. protected $dbname;
  189. protected $con;
  190.  
  191. public function __construct( $config )
  192. {
  193. try
  194. {
  195. #array com dados do banco
  196. $this->config = $config;
  197. # Recupera os dados de conexao do config
  198. $this->dbname = $this->config['dbname'];
  199. $this->driver = $this->config['driver'];
  200. $this->host = $this->config['host'];
  201. $this->port = $this->config['port'];
  202. $this->user = $this->config['user'];
  203. $this->pass = $this->config['password'];
  204. # instancia e retorna objeto
  205. $this->con = @mysql_connect( "$this->host", "$this->user", "$this->pass" );
  206. @mysql_select_db( "$this->dbname" );
  207. if( !$this->con )
  208. {
  209. throw new Exception( "Falha na conex�o MySql com o banco [$this->dbname] em " . DATABASEDIR . "database.conf.php" );
  210. }
  211. else
  212. {
  213. return $this->con;
  214. }
  215. }
  216. catch( Exception $e )
  217. {
  218. echo $e->getMessage();
  219. exit;
  220. }
  221. return $this;
  222. }
  223.  
  224. public function query( $query = '' )
  225. {
  226. try
  227. {
  228. if( $query == '' )
  229. {
  230. throw new Exception( 'mysql query: A query deve ser informada como parâmetro do método.' );
  231. }
  232. else
  233. {
  234. $this->query = $query;
  235. $this->result = @mysql_query( $this->query );
  236. if(!$this->result)
  237. {
  238. $this->response = "Erro " .mysql_errno()." => ". mysql_error();
  239. }
  240. else
  241. {
  242. $this->response = "success";
  243. }
  244. }
  245. }
  246. catch( Exception $e )
  247. {
  248. echo $e->getMessage();
  249. exit;
  250. }
  251. return $this;
  252. }
  253.  
  254. public function fetchAll()
  255. {
  256. $this->fetchAll = "";
  257. while( $row = @mysql_fetch_array( $this->result, MYSQL_ASSOC ) )
  258. {
  259. $this->fetchAll[] = $row;
  260. }
  261. return $this->fetchAll;
  262. }
  263.  
  264. public function rowCount()
  265. {
  266. return @mysql_affected_rows();
  267. }
  268.  
  269. public function limit( $limit, $offset )
  270. {
  271. return "LIMIT " . (int) $limit . "," . (int) $offset;
  272. }
  273. }
  274. /* end file */
  275.  
  276. **database.conf.php**
  277.  
  278. <?php
  279.  
  280. $databases = array(
  281. # MYSQL
  282. 'default' => array
  283. (
  284. 'driver' => 'mysql',
  285. 'host' => 'localhost',
  286. 'port' => 3306,
  287. 'dbname' => 'dbname',
  288. 'user' => 'root',
  289. 'password' => '',
  290. 'emailAdmin' => 'e-mail.com'// email para receber mensagens do chat
  291. )
  292. );
  293.  
  294. <?php
  295.  
  296. Class Conexao extends PDO
  297. {
  298.  
  299. protected $config;
  300. protected $driver;
  301. protected $sgbd;
  302. protected $host;
  303. protected $port;
  304. protected $user;
  305. protected $pass;
  306. protected $dbname;
  307. protected $strcon;
  308. protected $con;
  309.  
  310. public function __construct( $config )
  311. {
  312. try
  313. {
  314. #array com dados do banco
  315. $this->config = $config;
  316. # Recuperando os dados de conexao do driver
  317. $this->dbname = $this->config['dbname'];
  318. $this->driver = $this->config['driver'];
  319. $this->sgbd = $this->config['sgbd'];
  320. $this->host = $this->config['host'];
  321. $this->port = $this->config['port'];
  322. $this->user = $this->config['user'];
  323. $this->pass = $this->config['password'];
  324. $this->strCon = "$this->sgbd:host=$this->host;port=$this->port;";
  325. # instancia e retorna objeto PDO
  326. $this->con = parent :: __construct( "$this->strCon dbname=$this->dbname", $this->user, $this->pass, array( PDO::ATTR_PERSISTENT => true ) );
  327. return $this->con;
  328. }
  329. catch( PDOException $e )
  330. {
  331. echo 'A Conexão falhou: ' . $e->getMessage();
  332. exit;
  333. }
  334. }
  335.  
  336. public function close()
  337. {
  338. unset( $this->con );
  339. unset( $this->dbname );
  340. unset( $this->config );
  341. }
  342. }
  343. /* end file */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement