Locked Posted November 30, 2009 Share Posted November 30, 2009 global $mysqli; $stmt = $mysqli->prepare('SELECT user_name from `user_details` where user_email = ?'); $stmt->bind_param('s', $var); $stmt->execute() or $this->myerror[] = $stmt->error; echo $stmt->affected_rows; $stmt->affected_rows returns '-1' which would indicate a error but i dont see why it would error (Just started learning mysqli) Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/ Share on other sites More sharing options...
premiso Posted November 30, 2009 Share Posted November 30, 2009 Perhaps there is an error? Unsure how your script works have you tried printing out the $this->myerror array and seeing if there was indeed an error and what that error was? Aside from that, the SQL looks fine as far as I can tell. Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968545 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 mysqli_stmt->affected_rows does this - Returns the number of rows affected by INSERT, UPDATE, or DELETE query For a SELECT query you would want to use $stmt->num_rows Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968547 Share on other sites More sharing options...
premiso Posted November 30, 2009 Share Posted November 30, 2009 I need to start using MySQLi and can MySQL lol. Well at least the SQL was correct Just wrong function (feels like a dork for not reading the manual thoroughly). Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968549 Share on other sites More sharing options...
Locked Posted November 30, 2009 Author Share Posted November 30, 2009 For SELECT statements mysqli_affected_rows() works like mysqli_num_rows(). Connection <?php $mysqli = new mysqli("localhost","",,""); if(mysqli_connect_errno() > 0) { printf("Connection detail: %s.\n", mysqli_connect_error()); exit(); } $mysqli->autocommit(0); global $mysqli; ?> Other file include ("_connect.php"); public $myerror = array(); function check_name($var) { global $mysqli; $stmt = $mysqli->prepare('SELECT user_name from `user_details` where user_email = ?'); $stmt->bind_param('s', $var); $stmt->execute() or $this->myerror[] = $stmt->error; echo $stmt->affected_rows; if ($stmt->affected_rows > 0) { $this->myerror[] = 'This email is already in use.'; } (count($this->myerror) > 0) ? $return = TRUE : $return = FALSE; print_r($this->myerror); $stmt->close(); return $return; } myerror only returns array() Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968552 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 Except that you are using prepared statements and you are not using mysqli->affected_rows and any definition found in the manual concerning mysqli->affected_rows does not apply to prepared statements. You are using $stmt->affected_rows and it does not do what you think for a SELECT query. Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968558 Share on other sites More sharing options...
Locked Posted November 30, 2009 Author Share Posted November 30, 2009 I changed it to $stmt->num_rows, and it returns 0. If i run the same sql statment in phpmyadmin it returns 1 row Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968561 Share on other sites More sharing options...
Locked Posted December 1, 2009 Author Share Posted December 1, 2009 Never mind, still not working Quote Link to comment https://forums.phpfreaks.com/topic/183489-mysqli-question/#findComment-968608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.