Created
May 15, 2012 17:29
-
-
Save lean8086/2703504 to your computer and use it in GitHub Desktop.
Allows to connect to a database from PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Database { | |
private $HOST = "...Your hostname or IP here..."; | |
private $USER = "...Username to log into database..."; | |
private $PASS = "...Password to log into database..."; | |
private $DDBB = "...Name of database..."; | |
private function connect() { | |
$c = mysql_connect($this->HOST, $this->USER, $this->PASS); | |
mysql_select_db($this->DDBB, $c); | |
return $c; | |
} | |
public function get($q) { | |
$c = $this->connect(); | |
$r = mysql_query($q, $c); | |
while($t = mysql_fetch_assoc($r)) $a[] = $t; | |
mysql_free_result($r); | |
mysql_close($c); | |
return $a; | |
} | |
public function set($q) { | |
$c = $this->connect(); | |
$r = mysql_query($q, $c); | |
mysql_close($c); | |
return $r; | |
} | |
}; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment