Lastinsertid problem

Hi, Can you help me please on this, i want to get the last inserted id but it gives me on this error

72SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Here is my code


function addCredit($a,$b){

    try{

        $con = new Connection();
        $dbh = $con->dbconnection();

        $dbq=$dbh->prepare('INSERT into credit (cr_x,cr_y) values (?,?)');
        $dbq->execute(array($a,$b));

        $id = $dbh->lastInsertId();

        echo $id;

        $dbh=null;

        return "Completed";


    }

    catch(PDOException $e){
        return $e->getMessage();
    }

}





Thank you in advance.

I think it doesn’t give the error on the line with the lastInsertId, but on the execution of the insert query itself.

Hi my insert statement is working i already tried to insert in my db,but the time when i want to get the lastinsertid,the error occurs…

Sorry my bad,…I apologize,…yes i got wrong parameter in other function that is why it throws error…

Thank you for giving me this idea :slight_smile:

You’re welcome. I’m glad you solved your problem :slight_smile: