ajoo Posted May 12, 2017 Share Posted May 12, 2017 Hi all, I have this simple query $query = 'SELECT count(ID), col1, col2, col3 FROM table WHERE email = ?'; // I know I have used capitals for ID $stmt = $link->prepare($query); $stmt->bind_param('s',$email); which works great in xampp but gives a FATAL ERROR when I run it on a server. Uncaught Error: Call to a member function bind_param() on boolean in /var/www/html/ all the column names, tables names etc. in the query are correct but the query seems to fail so prepare must be returning a false value. Hence the error. Anyone has any idea what's going on? Thanks loads ! Quote Link to comment Share on other sites More sharing options...
requinix Posted May 12, 2017 Share Posted May 12, 2017 Check $link->error for an error message. 1 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 12, 2017 Share Posted May 12, 2017 If you get false in case of an error, then your mysqli error reporting is fudged up or missing altogether. Fix that. I'm pretty sure I already gave you the code (the one with the mysqli driver). 1 Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 12, 2017 Author Share Posted May 12, 2017 (edited) Hi Requinix and Guru Jacques, Thanks for the response. @Requinix : Did check the $link -> error and the issue came out to be the same as the one in my last topic a few days ago answered by Guru Jacques. I should have checked the $link->error earlier but was loath to make changes in the php.ini in the server. But I did it in any case after you suggested. @Guru Jacques : I did not get a false in case of error. The error was properly reported once I turned on display errors. That what I wrote, I assumed that the query failed and returned a false. i.e. $stmt = $link -> prepare( ... ) was false. hmm was that right ? The issue has been once again triggered by the mysql_mode = only_full_group_by. I can easily rectify that by adding a group_by on say the id field. However I would like to avoid this query altogether if possible. This query is for checking if the $email is present in the table and its count. It can be multiple too and I may use that information elsewhere if ever in the future. So is there a better way to do this or should I just go ahead and add the group by to the end of the query? Thanks loads ! P.S. I guess all queries that use count(..) would need to be looked into. Not many though ! Edited May 12, 2017 by ajoo Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted May 12, 2017 Solution Share Posted May 12, 2017 I did not get a false in case of error. You did. That's what the error message you've posted means. A properly configured mysqli would have thrown an exception and stopped the entire script after failing to create the prepared statement. But your script kept running until it crashed when it tried to call bind_param() on the boolean value false. Again, something is wrong with your mysqli. It should not continue after an error, and you should not have to manually pull error messages out of $link->error. 1 Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 12, 2017 Author Share Posted May 12, 2017 hmm ! no wonder it said "Uncaught Error ". There was also something about the exception in that message. you should not have to manually pull error messages out of $link->error. So the error message should have been in the error.log and the same as given by $link->error ? And I need not have fiddled with the php.ini. Right ? I'll check it out as you have pointed out earlier. If I am still stuck I'll revert. Thanks a ton for that insight. Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 13, 2017 Author Share Posted May 13, 2017 Hi ! I'm pretty sure I already gave you the code (the one with the mysqli driver). Yes you did Guru Jacques and for anybody else who may be following this, it was in the thread : https://forums.phpfreaks.com/topic/300722-handling-exceptions-by-loading-a-page-with-a-safe-message/ A properly configured mysqli would have thrown an exception and stopped the entire script after failing to create the prepared statement. But your script kept running until it crashed when it tried to call bind_param() on the boolean value false. The mysqli error handling had got left commented out and that was the reason for the problem that you mentioned above. However it never occurred to me which you could see instantly ! So after the changes the error ( I made a few changes to the path and names) that I now receive is : PHP Fatal error: Uncaught mysqli_sql_exception: In aggregated query without GROUP BY,expression #2 of SELECT list contains nonaggregated column 'a_o.table.somecode'; this is incompatible with sql_mode=only_full_group_by in /var/www/html/path/to/vermail.php:217 \nStack trace:\n #0 /var/www/html/path/to/vermail.php(217): mysqli->prepare('SELECT count(ID...')\n #1 /var/www/html/path/to/vermail.php(294): send_password_mail(Object(mysqli), 'blk@fk.com')\n #2 {main}\n thrown in /var/www/html/path/to/verifymail.php on line 217, referer: http://ec2-152-166-185-167.am-west-1./path/to/vermail.php and it does proceed further. I hope it's fine now and I have finally got it correct. Thanks loads ! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 13, 2017 Share Posted May 13, 2017 That looks better. 1 Quote Link to comment 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.