From eda4ecab78a1b3dcd3d31c7b99d0e3799c385353 Mon Sep 17 00:00:00 2001 From: =devegpat Date: Sat, 10 Dec 2016 08:47:02 +0530 Subject: [PATCH 1/2] Now supports query strings/parameters and upgraded to mysqli --- system/model.php | 22 +++++++++++----------- system/pip.php | 9 +++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/system/model.php b/system/model.php index 04503ca..1f8aa52 100644 --- a/system/model.php +++ b/system/model.php @@ -8,19 +8,22 @@ 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); + $this->connection = new mysqli($config["db_host"],$config["db_username"],$config["db_password"],$config["db_name"]); + } public function escapeString($string) { - return mysql_real_escape_string($string); + return mysqli_real_escape_string($this->connection,$string); } public function escapeArray($array) { - array_walk_recursive($array, create_function('&$v', '$v = mysql_real_escape_string($v);')); - return $array; + $clean = []; + foreach ($array as $key => $value) { + $clean[$key] = mysqli_real_escape_string($this->connection,$value); + } + return $clean; } public function to_bool($val) @@ -45,17 +48,14 @@ public function to_datetime($val) public function query($qry) { - $result = mysql_query($qry) or die('MySQL Error: '. mysql_error()); - $resultObjects = array(); - - while($row = mysql_fetch_object($result)) $resultObjects[] = $row; + $result = $this->connection->query($qry) or die('MySQL Error: '. mysqli_error($this->connection)); - return $resultObjects; + return $result; } public function execute($qry) { - $exec = mysql_query($qry) or die('MySQL Error: '. mysql_error()); + $exec = mysqli_query($qry) or die('MySQL Error: '. mysqli_error()); return $exec; } diff --git a/system/pip.php b/system/pip.php index c69195c..0e4e0ea 100644 --- a/system/pip.php +++ b/system/pip.php @@ -11,6 +11,11 @@ function pip() // Get request url and script url $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; + + $temp = (strpos($_SERVER["REQUEST_URI"], "?")) ? strpos($_SERVER["REQUEST_URI"],"?") : strlen($_SERVER["REQUEST_URI"]); + + $request_url = substr($_SERVER['REQUEST_URI'],0,$temp); + $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; // Get our url path and trim the / of the left and the right @@ -25,6 +30,7 @@ function pip() // Get our controller file $path = APP_DIR . 'controllers/' . $controller . '.php'; + if(file_exists($path)){ require_once($path); } else { @@ -33,11 +39,14 @@ function pip() } // Check the action exists + if(!method_exists($controller, $action)){ $controller = $config['error_controller']; require_once(APP_DIR . 'controllers/' . $controller . '.php'); $action = 'index'; } + + // Create object and call method $obj = new $controller; From f6dfdc700a4d70573ab246f0f8a43430a6f7a63d Mon Sep 17 00:00:00 2001 From: =devegpat Date: Sat, 10 Dec 2016 08:50:08 +0530 Subject: [PATCH 2/2] mysqli_error() redone --- system/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/model.php b/system/model.php index 1f8aa52..ce3ed57 100644 --- a/system/model.php +++ b/system/model.php @@ -55,7 +55,7 @@ public function query($qry) public function execute($qry) { - $exec = mysqli_query($qry) or die('MySQL Error: '. mysqli_error()); + $exec = mysqli_query($qry) or die('MySQL Error: '. mysqli_error($this->connection)); return $exec; }