Jump to content

Need help using mysqli OOP


eldan88
Go to solution Solved by eldan88,

Recommended Posts

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);
    }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.