Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts

    multiple queries with prepared statements

    How would I get the number of queries successfully executed in a prepared statement?

    I have this, and it's returning an error of:
    Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, array given in /homepages/27/d418565624/htdocs/book/insert.php on line 8

    PHP Code:
    <?php
    require 'db_connect.php';
    $array_values=array(array("test""test"), array("Kay""example"), array("kena","194"));
    $prepared_query=mysqli_prepare($db"INSERT INTO `users` (`username`, `password`) 
    VALUES (?, ?)"
    );
    $i=0;
    foreach(
    $array_values as $row_value){
    mysqli_stmt_execute($row_value);
        if(
    mysqli_stmt_affected_rows()==1){
        
    $i++;
        }
    }

    if(
    $i==3){
    echo 
    "Data inserted.";
    }
    else{
    echo 
    "Data not Inserted.";
    }
    ?>
    Last edited by HDRebel88; 07-12-2012 at 07:19 AM.

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    124
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Solved with the following:

    PHP Code:
    <?php
    require 'db_connect.php';
    $array_values=array( array("test""test"), array("Kayci""example"), array("kena","194") );
    $prepared_query=mysqli_prepare($db"INSERT INTO `users` (`username`, `password`) 
    VALUES (?, ?)"
    );

    mysqli_stmt_bind_param($prepared_query'ss'$username$password);

    foreach(
    $array_values as $row_value){
    $username=$row_value[0];
    $password=$row_value[1];
    mysqli_stmt_execute($prepared_query);
    $num_affected+=mysqli_stmt_affected_rows($prepared_query);
    }

    if(
    $num_affected==3){
    echo 
    "Data inserted.";
    }
    else{
    echo 
    "Data not Inserted.";
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •