Advertisement
Guest User

Untitled

a guest
May 6th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. <?php
  2. class MySQL
  3. {
  4. public function __construct()
  5. {
  6. $this->Connect();
  7. }
  8.  
  9. # MySQL Credentials..
  10. Private $Hostname = 'localhost';
  11. Private $Username = 'root';
  12. Private $Password = '';
  13. Private $Database = 'framework';
  14.  
  15. function PingMySQLServer( $Connector )
  16. {
  17. // Ping the hostname provided in the Connect function.
  18. if( !mysql_ping( $Connector ) )
  19. {
  20. // Could not ping.
  21. return 0;
  22. }
  23. else
  24. {
  25. // Could ping. Possible restart of MySQL service just happened?
  26. return 1;
  27. }
  28. }
  29. private function Connect()
  30. {
  31. $Connector = @mysql_connect( $this->Hostname, $this->Username, $this->Password );
  32.  
  33. // Check the connector if it didn't work above.. Does it work now?
  34. if( !$Connector )
  35. {
  36. // Maybe it doesn't, maybe it's a server problem. This will ping the hostname.
  37. if ( $this->PingMySQLServer( $Connector ) == 0 )
  38. {
  39. // Display custom error message.
  40. exit( "Sorry, we're under maintenance right now." );
  41. }
  42. }
  43.  
  44. // Ignore any errors it trys to throw back..
  45. @mysql_select_db( $this->Database );
  46. }
  47. function ReturnQuery( $query )
  48. {
  49. // Maybe it doesn't, maybe it's a server problem. This will ping the hostname.
  50. if ( $this->PingMySQLServer( $this->Connect() ) == 0 )
  51. {
  52. // Display custom error message.
  53. exit( "Sorry, we're under maintenance right now." );
  54. }
  55.  
  56. return mysql_query( $query );
  57. }
  58. function ReturnRows( $query )
  59. {
  60. // Maybe it doesn't, maybe it's a server problem. This will ping the hostname.
  61. if ( $this->PingMySQLServer( $this->Connect() ) == 0 )
  62. {
  63. // Display custom error message.
  64. exit( "Sorry, we're under maintenance right now." );
  65. }
  66.  
  67. return mysql_num_rows( $query );
  68. }
  69. function ReturnArray( $query )
  70. {
  71. // Maybe it doesn't, maybe it's a server problem. This will ping the hostname.
  72. if ( $this->PingMySQLServer( $this->Connect() ) == 0 )
  73. {
  74. // Display custom error message.
  75. exit( "Sorry, we're under maintenance right now." );
  76. }
  77.  
  78. return mysql_fetch_array( $query );
  79. }
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement