/ Published in: PHP
                    
                                        
That's something quick. A basic php class to manage properly a database. Thanks to magic methods opening a database is almost automatic.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
class Database{
private $host = '127.0.0.1';
private $dbname = 'example';
private $dbpwd = '';
private $dbuser = 'root';
public $link;
function __construct(){
}
function __destruct(){
}
public static function filter($data){
else{
}
return $data;
}
// $table = string, $conditions = array, $limit = number
public static function readRecord( $table, $conditions, $limit=false ){
$query = "SELECT * FROM $table WHERE ";
foreach($conditions as $a => $b)
$query .= "$a = '".Database::filter($b)."' AND ";
}
// $table = string, $values = array
public static function addRecord( $table, $values ){
$q_1 = "INSERT INTO $table(";
$q_2 = ") VALUES(";
foreach($values as $field => $val){
$q_1 .= $field.', ';
$q_2 .= "'".Database::filter($val)."', ";
}
}
// $table = string, $conditions = array, $limit = number
public static function removeRecord( $table, $conditions, $limit=false ){
$query = "DELETE FROM $table WHERE ";
foreach($conditions as $a => $b)
$query .= "$a = '".Database::filter($b)."' AND ";
}
}
?>
URL: http://claudiobonifazi.com
Comments
 Subscribe to comments
                    Subscribe to comments
                
                