Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions system/model.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,71 @@
<?php

class Model {
class Model extends PDO{

private $connection;

public function __construct()
{
public function __construct(){
global $config;

$this->connection = mysql_pconnect($config['db_host'], $config['db_username'], $config['db_password']) or die('MySQL Error: '. mysql_error());
mysql_select_db($config['db_name'], $this->connection);

try{
$dsn = "mysql:dbname={$config['db_name']};host={$config['db_host']}";
$this->connection = parent::__construct($dsn, $config['db_username'], $config['db_password']);
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
return $e->getMessage();
}
}

public function escapeString($string)
{
//deprecated
public function escapeString($string){
return mysql_real_escape_string($string);
}

public function escapeArray($array)
{
//deprecated
public function escapeArray($array){
array_walk_recursive($array, create_function('&$v', '$v = mysql_real_escape_string($v);'));
return $array;
}

public function to_bool($val)
{
public function to_bool($val){
return !!$val;
}

public function to_date($val)
{
public function to_date($val){
return date('Y-m-d', $val);
}

public function to_time($val)
{
public function to_time($val){
return date('H:i:s', $val);
}

public function to_datetime($val)
{
public function to_datetime($val){
return date('Y-m-d H:i:s', $val);
}

public function query($qry)
{
$result = mysql_query($qry) or die('MySQL Error: '. mysql_error());
$resultObjects = array();
public function query($qry, $params=array()){
try{
$pdo = $this->prepare($qry);
$pdo->execute($params);

while($row = mysql_fetch_object($result)) $resultObjects[] = $row;
return $pdo->fetchAll(PDO::FETCH_OBJ);
}
catch(PDOException $e){
return $e->getMessage();
}

return $resultObjects;
}

public function execute($qry)
{
$exec = mysql_query($qry) or die('MySQL Error: '. mysql_error());
return $exec;
public function execute($qry, $params=array()){
try{
$pdo = $this->prepare($qry);
$pdo->execute($params);
return $pdo->rowCount();
}
catch(PDOException $e){
return $e->getMessage();
}
}

}
Expand Down