Guest User

Untitled

a guest
Oct 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. class libSQL
  4. {
  5. private $_sql_link;
  6. private $_sql_query;
  7. private $_sql_params;
  8. private $_sql_retval;
  9.  
  10. public function connect($host, $user, $pass)
  11. {
  12. $this->_sql_link = @mysql_connect($host, $user, $pass, true);
  13.  
  14. if(!$this->_sql_link)
  15. {
  16. $this->sendError('Cant connect to the MySQL Server.');
  17. }
  18. }
  19.  
  20. public function database($db)
  21. {
  22. if(!mysql_select_db($db))
  23. {
  24. $this->sendError('Cant connect to the Database.');
  25. }
  26. }
  27.  
  28. public function query($string)
  29. {
  30. $this->_sql_query = $string;
  31. }
  32.  
  33. public function bind($name, $value)
  34. {
  35. $this->_sql_params[$name] = $value;
  36. }
  37.  
  38. public function protect()
  39. {
  40. foreach($this->_sql_params as $name => $value)
  41. {
  42. $this->_sql_params[$name] = mysql_real_escape_string($value, $this->_sql_link);
  43. }
  44. }
  45.  
  46. public function execute()
  47. {
  48. foreach($this->_sql_params as $name => $value)
  49. {
  50. $this->_sql_query = str_replace("{!$name}", $value, $this->_sql_query);
  51. }
  52.  
  53. $this->_sql_params = array();
  54. $this->_sql_retval = @mysql_query($this->_sql_query, $this->_sql_link);
  55.  
  56. if(!$this->_sql_retval)
  57. {
  58. $this->sendError('Cant execute the Query.');
  59. }
  60. }
  61.  
  62. public function result()
  63. {
  64. return mysql_fetch_object($this->_sql_retval);
  65. }
  66.  
  67. public function disconnect()
  68. {
  69. mysql_close($this->_sql_link);
  70. }
  71.  
  72. private function sendError($msg)
  73. {
  74. die($msg);
  75. }
  76. }
  77.  
  78.  
  79. $sql = new libSQL();
  80.  
  81. $sql->connect("localhost", "root", "");
  82. $sql->database("phpmyadmin");
  83.  
  84. $sql->query("SELECT * FROM {!db} WHERE username = '{!name}' LIMIT 1;");
  85. $sql->bind('db', 'pma_history');
  86. $sql->bind('name', 'root');
  87. $sql->protect();
  88. $sql->execute();
  89.  
  90. // while($var = $sql->result()) ghet auch
  91. echo $sql->result()->username;
  92.  
  93. $sql->disconnect();
  94.  
  95. ?>
Add Comment
Please, Sign In to add comment