Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'ResultSet.php';
- class MySQLDatabase {
- private $host;
- private $source;
- private $username;
- private $password;
- private $url;
- private $db;
- function MySQLDatabase($host, $source, $username, $password=""){
- $this->host = $host;
- $this->source = $source;
- $this->username = $username;
- $this->password = $password;
- $this->url = "mysql:host=$host;dbname=$source";
- $this->db = new PDO($this->url, $username, $password);
- }
- public function selectAll($tableName){
- $ps = $this->db->query("SELECT * FROM $tableName");
- return new ResultSet($ps);
- }
- public function executeSelect($query){
- $ps = $this->db->query($query);
- return new ResultSet($ps);
- }
- public function select($tableName, $key, $value){
- $ps = $this->db->query("SELECT * FROM $tableName WHERE $key=$value");
- return new ResultSet($ps);
- }
- public function insert($tableName, $row){
- $req = "INSERT INTO $tableName VALUES (\"" . $row[0] . "\"";
- $n = count($row);
- for($i = 1; $i < $n; $i++){
- $req = $req . ", \"" . $row[$i] . "\"";
- }
- $req = $req . ")";
- echo $req;
- return $this->db->exec($req);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement