Created
March 25, 2017 15:20
-
-
Save Deviad/40ad3272e3e474147cf5540b39684924 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* @author Davide Pugliese | |
* @uses PDO | |
* | |
* This is a little engine to run queries the smart way. | |
* | |
*/ | |
namespace Db; | |
//include (__DIR__) . '/DbMgmt.php'; | |
use Db\DbMgmt as DbMgmt; | |
use \PDO; | |
class DbObj | |
{ | |
public $the_table = null; | |
public $the_attrs = null; | |
public $projection = null; | |
public $the_values; | |
public $dbConnection; | |
public function __constructor () { | |
$this->dbConnection = new DbMgmt(); | |
} | |
public function addObj($the_table, $the_attrs, $the_values) | |
{ | |
// echo "INTO THE GENERIC FUNCTION"; | |
// var_dump($the_table); | |
// var_dump($the_attrs); | |
// var_dump($the_values); | |
$sql = "INSERT INTO $the_table ( $the_attrs ) VALUES ( $the_values );"; | |
// var_dump($sql); | |
$pdo_obj = $this->dbConnection->newConn(); //get the pdo object | |
$stmt = $pdo_obj->prepare($sql); | |
var_dump($sql); | |
$stmt->execute(); | |
// echo "Data inserted!"; | |
} | |
public function rmObj($the_table, $the_attrs, $the_values) | |
{ | |
$sql = "DELETE FROM $the_table WHERE ($the_attrs) = ( $the_values );"; | |
$pdo_obj = $this->dbConnection; //get the pdo object | |
$stmt = $pdo_obj->prepare($sql); | |
$stmt->execute(); | |
echo "Data deleted!"; | |
} | |
public function getObj($projection, $the_table, $condition) | |
{ | |
$sql = "SELECT {$projection} FROM {$the_table} {$condition}"; | |
$pdo_obj = $this->dbConnection; //get the pdo object | |
$stmt = $pdo_obj->prepare($sql); | |
$stmt->execute(); | |
return $stmt->fetchAll(PDO::FETCH_ASSOC); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment