eldan88 Posted April 7, 2014 Share Posted April 7, 2014 Hey Guys. I am new to using mysqli OOP style, and I am currently switching my code from procedural mysql to OOP. I have create a query statement, and every time I run the query statement I get the following error..... Warning: mysqli::query() [mysqli.query]: Empty.... I just don't see how this is empty?? Below is my code.... $mysqli = new mysqli('localhost', 'root'); // I know I don't have a password set up.. but it still works i tested it // Insert the values in the database only if there are no errors in the validation erros variable if(empty($validationErrors)) { $query = "INSERT INTO checkout( store_id , confirmation_number , is_confirmed , sent_to_reminder , set_reminder , reminder_duration , is_registered ) VALUES ( {$post_values->store_id}, {$post_values->confirmation_number}, 0 , {$post_values->sent_to_reminder} , {$post_values->set_reminder} , '{$post_values->reminder_duration}' , {$post_values->registered_user} ) ;"; $result = $mysqli->query($query); if (!$mysqli->query($result)) { printf("Error: %s\n", $mysqli->error); } Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/ Share on other sites More sharing options...
mikosiko Posted April 7, 2014 Share Posted April 7, 2014 $result = $mysqli->query($query); // Do you know what $mysqli->query($query) produce as result? http://us1.php.net/mysqli_query (Check "Return Values")if (!$mysqli->query($result)) { // Then the error here should be obvious printf("Error: %s\n", $mysqli->error); } Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/#findComment-1475309 Share on other sites More sharing options...
Solution eldan88 Posted April 7, 2014 Author Solution Share Posted April 7, 2014 mikosiko. No that actually is not the reason why it didn't work. I found that I was missing my db name and didn't pass in an empty string for password. Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/#findComment-1475325 Share on other sites More sharing options...
mikosiko Posted April 7, 2014 Share Posted April 7, 2014 so are you saying that this line in your code was correct? if (!$mysqli->query($result)) { don't think so (definely not ok) ... but if you fixed your code already good for you Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/#findComment-1475328 Share on other sites More sharing options...
mikosiko Posted April 7, 2014 Share Posted April 7, 2014 revisiting your code and your comments I think that you are right... the warning message "Warning: mysqli::query() [mysqli.query]: Empty.... I just don't see how this is empty??" should have been one of several warning message that you got, due to the fact that as you said you were missing the password and dbname and not as result of the line that I did pointed out, however, that line (after you fixed the instantation of the mysqli object) should give you a SQL syntax error most likely... my link to read about result values still apply in this case. Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/#findComment-1475331 Share on other sites More sharing options...
eldan88 Posted April 7, 2014 Author Share Posted April 7, 2014 No No. In that case its better to use the $db->connect_error; $db = new mysqli("$host", "$username" , "$password", "$db_name");if($db->connect_errno){ echo $db->connect_error; //die("Sorry, we are having some problems");} It will tell you exactly what the issue is. The the mysql result is not relevant to this topic.... Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/#findComment-1475336 Share on other sites More sharing options...
eldan88 Posted April 7, 2014 Author Share Posted April 7, 2014 But thanks for trying to help Quote Link to comment https://forums.phpfreaks.com/topic/287588-need-help-using-mysqli-oop/#findComment-1475337 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.