Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference between execute functions

What is the difference between using execute_query[1] or using the prepare then execute [2] and when do we use the bind parameter and why? like in example [2] we already gave the variables within the execute so when is the bind parameter more useful?

[1]

        $stmt = $db->execute_query($Update, [$Date, $Email]);

[2]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    $stmt = $db->prepare("INSERT INTO Users (Username, Email, Password, Creation_Date, VIP, Admin) VALUES (?,?,?,?,?,?)");
    $stmt->execute([
        $Username, 
        $Email,
        $Password,
        $Creation_date,
        $VIP,
        $Admin,
    ]);

Please give an in your own words explanation as i have hard time understanding documentations and they aren’t always clear!
Thanks in advance!

>Solution :

execute_query() is simply a shortcut that allows you to combine prepare(), bind_param(), execute(), and get_result() into a single call.

Since you don’t have a mysqli_stmt object, status information about the query will be put into the $db object. For example, instead of $stmt->affected_rows you use $db->affected_rows.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading