Guest User

Untitled

a guest
Aug 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. How to modify a mysql_pconnect function in order to count queries
  2. $hostname = "localhost";
  3. $database = "listings";
  4. $username = "joe";
  5. $password = "1234";
  6.  
  7. $my_connection = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
  8.  
  9. class MySQLWrapper
  10. {
  11.  
  12. private $_link;
  13. private $_totalQueries;
  14.  
  15. /**
  16. * Connects to the database server
  17. *
  18. * @param string $hostname
  19. * @param string $username
  20. * @param string $password
  21. *
  22. */
  23. public function connect($hostname, $username, $password) {
  24. if (is_null($this->_link)) {
  25. $this->_link = mysql_pconnect($hostname, $username, $password);
  26. }
  27. }
  28.  
  29. /**
  30. * Performs query
  31. *
  32. * @param string $sql
  33. * @return resource
  34. */
  35. public function query($sql) {
  36. $this->_totalQueries++;
  37. return mysql_query($sql, $this->_link);
  38. }
  39.  
  40. /**
  41. * Returns count of queries made
  42. * @return int
  43. */
  44. public function getTotalQueryCount() {
  45. return $this->_totalQueries;
  46. }
  47. }
Add Comment
Please, Sign In to add comment