Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. include 'ResultSet.php';
  3.  
  4. class MySQLDatabase {
  5.  
  6. private $host;
  7. private $source;
  8. private $username;
  9. private $password;
  10. private $url;
  11. private $db;
  12.  
  13. function MySQLDatabase($host, $source, $username, $password=""){
  14. $this->host = $host;
  15. $this->source = $source;
  16. $this->username = $username;
  17. $this->password = $password;
  18. $this->url = "mysql:host=$host;dbname=$source";
  19. $this->db = new PDO($this->url, $username, $password);
  20. }
  21.  
  22. public function selectAll($tableName){
  23. $ps = $this->db->query("SELECT * FROM $tableName");
  24. return new ResultSet($ps);
  25. }
  26.  
  27. public function executeSelect($query){
  28. $ps = $this->db->query($query);
  29. return new ResultSet($ps);
  30. }
  31.  
  32. public function select($tableName, $key, $value){
  33. $ps = $this->db->query("SELECT * FROM $tableName WHERE $key=$value");
  34. return new ResultSet($ps);
  35. }
  36.  
  37. public function insert($tableName, $row){
  38. $req = "INSERT INTO $tableName VALUES (\"" . $row[0] . "\"";
  39. $n = count($row);
  40. for($i = 1; $i < $n; $i++){
  41. $req = $req . ", \"" . $row[$i] . "\"";
  42. }
  43. $req = $req . ")";
  44. echo $req;
  45. return $this->db->exec($req);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement