mysqli affected_rows = -1, but error and errno are blank
Posted: Thu Jun 03, 2010 3:44 am
Hello,
I'm trying to prepare a bound-parameter statement, but this problem has been holding me back for quite some time. (I'm teaching myself how to use mysqli, so my theory probably isn't perfect
)
I have a query that works properly from phpmyadmin (with actual values substituted)
but when i try to prepare the query string, my mysqli object's affected_rows property gets set to -1, but error and errno are both set to 0 and '' (empty string) respectively.
The documentation for mysqli -> affected_rows says that a value of -1 means the query produced and error, but as I am given no error message and my syntax works with phpmyadmin, i'm not sure what's going on
EDIT 06.29.2010: THIS CODE IS NOT QUITE UP TO DATE; SEE LATER POSTS!
This is my prepare() method:
Here's my debugClass:
and here's the debug info i have the program output:
I sure hope it doesn't have to do with my setting 'error_prepend_string' to "OH SNAP"...
Any help is greatly appreciated!
I'm trying to prepare a bound-parameter statement, but this problem has been holding me back for quite some time. (I'm teaching myself how to use mysqli, so my theory probably isn't perfect
I have a query that works properly from phpmyadmin (with actual values substituted)
but when i try to prepare the query string, my mysqli object's affected_rows property gets set to -1, but error and errno are both set to 0 and '' (empty string) respectively.
The documentation for mysqli -> affected_rows says that a value of -1 means the query produced and error, but as I am given no error message and my syntax works with phpmyadmin, i'm not sure what's going on
EDIT 06.29.2010: THIS CODE IS NOT QUITE UP TO DATE; SEE LATER POSTS!
This is my prepare() method:
Code: Select all
[php=db_class.php|557]
protected function prepare () {
$this -> debugClassObj -> head(__METHOD__);
$this -> debugClassObj -> print_var($this -> mysqliObj,'$this -> mysqliObj',__LINE__);
$this -> debugClassObj -> print_var($this -> mysqliStmtObj,'$this -> mysqliStmtObj',__LINE__);
$this -> query['prepare'] = "SELECT {$this -> query['columns']} FROM `{$this -> query ['table']}` WHERE ";
$count = 0;
foreach ($this -> query['where'] as $k => $v) {
if ($count ==0) {
$this -> query['prepare'] .= "'$k'=?";
} else {
$this -> query['prepare'] .= "AND '$k'=?";
}
$count++;
}
$this -> debugClassObj -> print_var($this -> query['prepare'],'$this -> query[\'prepare\']',__LINE__);
$this -> debugClassObj -> message('$this -> mysqliStmtObj -> prepare ("'. $this -> query['prepare'] .'")',__CLASS__,__LINE__);
$this -> mysqliStmtObj = $this -> mysqliObj -> prepare ($this -> query['prepare']);
$this -> debugClassObj -> print_var($this -> mysqliObj,'$this -> mysqliObj',__LINE__);
$this -> debugClassObj -> print_var($this -> mysqliStmtObj,'$this -> mysqliStmtObj',__LINE__);
if ($this -> mysqliObj -> affected_rows == -1) {
die (__LINE__.': '.__CLASS__.'::mysqliObj -> affected_rows == -1! why is this??');
} else {
$this -> bindParams ();
}
$this -> debugClassObj -> foot();
}
[/php]Code: Select all
[php=debug_class.php]
/*
* This class is used to expedite the process of displaying debug information
*/
class debugClass {
private $mode = 0;
function __construct($mode) {
$this -> mode = $mode;
if ($this -> mode) {
$this -> head(__METHOD__);
$this -> foot();
}
}
function print_var ($var,$name,$line=NULL) {
if ($this -> mode) {
echo "<pre>$name: $line</p><blockquote><pre>";
print_r ($var);
echo "</pre></blockquote>";
}
}
///////////////////////////////////////////////////////////////////////////////////////
function head($method,$params=NULL) {
if ($this -> mode) {
$output = "<p><pre>$method (";
if (is_array($params)) {
$i = 0;
$count = count($params);
foreach ($params as $v) {
if ($i == 0) {
$output .= "'$v'";
} else {
$output .= ", '$v'";
}
$i++;
}
if (substr_count($output,',') == 1) {
str_replace(',','',$output);
}
} else {
$output .= $params;
}
$output .= ") {</pre></p><blockquote>";
echo $output;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
function foot() {
if ($this -> mode) {
echo "</blockquote><p><pre>}</pre></p>";
}
}
///////////////////////////////////////////////////////////////////////////////////////
function message ($message,$class,$line=null) {
if ($this -> mode) {
echo "<pre><p><b>$class::$line</b>: $message</p></pre>";
}
}
}
[/php]Code: Select all
dbClass::prepare () {
560: $this -> mysqliObj
mysqli Object
(
[affected_rows] => 9
[client_info] => 5.0.27
[client_version] => 50027
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[field_count] => 6
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.1.41-3ubuntu12.1
[server_version] => 50141
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 153
[warning_count] => 0
)
561: $this -> mysqliStmtObj
NULL
575: $this -> query['prepare']
SELECT `id`, `name`, `website`, `dateCreate`, `frozen` FROM `accounts` WHERE 'id'=?
579 - dbClass:: "$this -> mysqliStmtObj -> prepare ("SELECT `id`, `name`, `website`, `dateCreate`, `frozen` FROM `accounts` WHERE 'id'=?")"
584: $this -> mysqliObj
mysqli Object
(
[affected_rows] => -1
[client_info] => 5.0.27
[client_version] => 50027
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[field_count] => 6
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.1.41-3ubuntu12.1
[server_version] => 50141
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 153
[warning_count] => 0
)
585: $this -> mysqliStmtObj
mysqli_stmt Object
(
[affected_rows] => 0
[insert_id] => 0
[num_rows] => 0
[param_count] => 1
[field_count] => 5
[errno] => 0
[error] =>
[sqlstate] => 00000
[id] => 1
)
586: $this -> mysqliStmtObj2
mysqli_stmt Object
OH SNAP
Warning: print_r() [function.print-r.html]: Property access is not allowed yet in /home/jeff/www/techjeff/include/classes/debug_class.php on line 29
OH SNAP
Warning: print_r() [function.print-r.html]: Property access is not allowed yet in /home/jeff/www/techjeff/include/classes/debug_class.php on line 29
OH SNAP
Warning: print_r() [function.print-r.html]: Property access is not allowed yet in /home/jeff/www/techjeff/include/classes/debug_class.php on line 29
OH SNAP
Warning: print_r() [function.print-r.html]: Property access is not allowed yet in /home/jeff/www/techjeff/include/classes/debug_class.php on line 29
OH SNAP
Warning: print_r() [function.print-r.html]: Property access is not allowed yet in /home/jeff/www/techjeff/include/classes/debug_class.php on line 29
OH SNAP
Warning: print_r() [function.print-r.html]: Property access is not allowed yet in /home/jeff/www/techjeff/include/classes/debug_class.php on line 29
(
[affected_rows] =>
[insert_id] =>
[num_rows] =>
[param_count] =>
[field_count] =>
[errno] => 0
[error] =>
[sqlstate] => 00000
[id] =>
)
589: die ("dbClass::mysqliObj -> affected_rows == -1! why is this??")
accountClass::__destruct () {
}
dbClass::__destruct () {
dbClass::disconnect () {
}
}
Any help is greatly appreciated!