From ff4e74a0ecdb26d5dc0f687d76bfc6fdf120eba4 Mon Sep 17 00:00:00 2001 From: rylon Date: Sun, 4 May 2014 18:39:10 +0200 Subject: [PATCH] fixed several smaller bugs in system (json,mysql,autoload) --- db/connection/ConnectionMYS.php | 5 ++--- db/result/ResultMysqliPrepare.php | 8 ++++---- log/error_handler/error_handler_dbwriter.php | 6 ++++-- log/result/JsonResult.php | 10 +++++++--- system/autoload.php | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/db/connection/ConnectionMYS.php b/db/connection/ConnectionMYS.php index 18d65e8..2dc4bc1 100644 --- a/db/connection/ConnectionMYS.php +++ b/db/connection/ConnectionMYS.php @@ -30,10 +30,9 @@ class ConnectionMYS extends ConnectionAbstr { $binds = array($prepStmt,null); for($i =0; $i < \count($values);$i++){ $types .= self::getPrepareValueType($values[$i]); - $binds[] = &$values[$i]; - } + $binds[] = &$values[$i];} $binds[1] = $types; - \call_user_func_array('mysqli_stmt_bind_param', $binds); + \call_user_func_array('mysqli_stmt_bind_param', $binds); //you need 2 append the parameters - thats the right way to do that. if(!mysqli_stmt_execute($prepStmt)){ throw new \SYSTEM\LOG\ERROR("Could not execute prepare statement: ". \mysqli_stmt_error($prepStmt));} diff --git a/db/result/ResultMysqliPrepare.php b/db/result/ResultMysqliPrepare.php index dd43ee4..7d5dcd4 100644 --- a/db/result/ResultMysqliPrepare.php +++ b/db/result/ResultMysqliPrepare.php @@ -22,11 +22,11 @@ class ResultMysqliPrepare extends \SYSTEM\DB\Result{ return;} while ($field = $this->meta->fetch_field() ) { - $this->binds[$field->name] = &$this->binds[$field->name];} + $this->binds[$field->table.'.'.$field->name] = &$this->binds[$field->table.'.'.$field->name];} //fix for ambiguous fieldnames \mysqli_free_result($this->meta); - - call_user_func_array(array($this->res, 'bind_result'), $this->binds); + + call_user_func_array(array($this->res, 'bind_result'), $this->binds); //you need 2 append the parameters - thats the right way to do that. } public function __destruct() { @@ -48,7 +48,7 @@ class ResultMysqliPrepare extends \SYSTEM\DB\Result{ public function next($object = false, $result_type = MYSQL_BOTH){ if(\mysqli_stmt_fetch($this->res)){ foreach( $this->binds as $key=>$value ){ - $row[ $key ] = $value;} + $row[substr($key, strpos($key, '.')+1)] = $value;} //fix for ambiguous fieldnames return $row;} return NULL; } diff --git a/log/error_handler/error_handler_dbwriter.php b/log/error_handler/error_handler_dbwriter.php index a05ac25..64fa717 100644 --- a/log/error_handler/error_handler_dbwriter.php +++ b/log/error_handler/error_handler_dbwriter.php @@ -13,12 +13,14 @@ class error_handler_dbwriter extends \SYSTEM\LOG\error_handler { \SYSTEM\DBD\SYS_LOG_INSERT::Q1( array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(), getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5), $_SERVER["SERVER_NAME"],$_SERVER["SERVER_PORT"],$_SERVER['REQUEST_URI'], serialize($_POST), - array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null,$_SERVER['HTTP_USER_AGENT'], + array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null, + array_key_exists('HTTP_USER_AGENT',$_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : null, ($user = \SYSTEM\SECURITY\Security::getUser()) ? $user->id : null, $thrown ? 1 : 0), array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(), getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5),date('Y-m-d H:i:s', microtime(true)), $_SERVER["SERVER_NAME"],$_SERVER["SERVER_PORT"],$_SERVER['REQUEST_URI'], serialize($_POST), - array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null,$_SERVER['HTTP_USER_AGENT'], + array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null, + array_key_exists('HTTP_USER_AGENT',$_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : null, ($user = \SYSTEM\SECURITY\Security::getUser()) ? $user->id : null,$thrown)); if(\property_exists(get_class($E), 'logged')){ $E->logged = true;} //we just did log diff --git a/log/result/JsonResult.php b/log/result/JsonResult.php index 4bb0f69..d66d8f2 100644 --- a/log/result/JsonResult.php +++ b/log/result/JsonResult.php @@ -21,12 +21,16 @@ class JsonResult extends \SYSTEM\LOG\AbstractResult { //send Header \SYSTEM\HEADER::JSON(); - return msgpack_pack($json); + if($json = msgpack_pack($json)){ + return $json;} + throw new \SYSTEM\LOG\ERROR('MSGPack could not be encoded'); } else { //send Header \SYSTEM\HEADER::JSON(); - - return json_encode($json); + + if($json = json_encode($json)){ + return $json;} + throw new \SYSTEM\LOG\ERROR('JSON could not be encoded'); } } diff --git a/system/autoload.php b/system/autoload.php index 15afe2e..df6bbab 100644 --- a/system/autoload.php +++ b/system/autoload.php @@ -60,7 +60,7 @@ class autoload { public static function autoload($class){ $classns = self::getClassNamespaceFromClass($class); - if(!self::autoload_($classns[0],$classns[1]) || !class_exists($class)){ + if(!self::autoload_($classns[0],$classns[1]) || (!class_exists($class) && !interface_exists($class))){ throw new \SYSTEM\LOG\ERROR("Class not found: ".$class);} return true;