Jump to content

query works great in xampp but not on server


ajoo

Recommended Posts

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 !

 


 

 

Link to comment
Share on other sites

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 ! ::)  :happy-04:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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,

 

and it does proceed further.

 

I hope it's fine now and I have finally got it correct. 

 

Thanks loads !

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.