Ejemplo n.º 1
0
 /**
  * Create an empty model class instance that corresponds to a table in the 
  * database. For all columns there will be getters and setters (magic methods).
  * With the instance you will be able to fetch/change data from the database. 
  * @param string $className The model class you wish to create.
  */
 public function __construct($className)
 {
     $this->className = $className;
     $db = new DBConnection();
     $columns = $db->get_table_columns_names($this->convert_to_table_name($className));
     foreach ($columns as $c) {
         $this->classFields[$c] = null;
     }
     // Ignore: it's for debugging purposes. Used in to_dump() method.
     ModelTemplate::$currentInstanceId++;
     $this->instanceId = ModelTemplate::$currentInstanceId;
 }
Ejemplo n.º 2
0
var_dump($db->select('truck', '*', 'id', $lastInsertedId));
echo '</p>';
echo '<p> Some columns: ';
var_dump($db->select('truck', array('brand', 'age'), 'id', $lastInsertedId));
echo '</p>';
/*
 * SELECT ALL TEST.
 */
$db->insert('truck', array('brand' => 'Mercedes', 'age' => 3));
echo '<p> All rows and columns: ';
var_dump($db->select('truck', '*'));
/*
 * UPDATE TEST.
 */
echo '<p> Before update: ';
var_dump($db->select('truck', '*', 'id', $lastInsertedId));
echo '</p>';
$db->update('truck', array('vehicle_capacity' => 0, 'brand' => 'MAN', 'age' => 0), $lastInsertedId);
echo '<p> After update: ';
var_dump($db->select('truck', '*', 'id', $lastInsertedId));
echo '</p>';
/*
 * DELETE TEST.
 */
echo '<p> Deleted rows: ' . $db->delete('truck', $lastInsertedId) . '</p>';
echo '<p> Deleted rows: ' . $db->delete('truck', $lastInsertedId + 1) . '</p>';
/*
 * GET TABLE COLUMNS NAMES TEST.
 */
var_dump($db->get_table_columns_names('truck'));