Jump to content

Posting to autoincrement field in mysql Database using PEAR DB execute insert


pquery

Recommended Posts

I'm trying to prepare a PHP / PEAR statement for insertion into my MySQL database, but I just can't seem to find where or how to place the  field for the auto-increment ID field at the beginning of the table? (an nothing seems to explain this in the documentation I've seen so far.

 

(NULL) doesn't seem to be what I want inserted in this placeholder since it's a non-null field, so I was hoping someone around here knew how to do this (or could point me the way to a helpful link)

 

here's an example of what I'm trying to accomplish:

 

require_once 'dsn.php';

$data = array( "",3, 'Cameron', 'Kirk');

$sth = $db->prepare('INSERT INTO employees VALUES (?, ?,?)');
$res = $db->executeMultiple($sth, $data);

if (DB::isError($res)) {         // Check the result object in case there
    die($res->getMessage());  // was an error, and handle it here.
}


 

 

Now my dsn conncetion is fine, but I keep getting the error message of : DB Error: mismatch

 

There's the right number of fields for that table, just the blank is where the autonumber should be.

Link to comment
Share on other sites

Match the argument count then, blank or not, you're still passing an array of 4 values to a statement with 3 place holders.  Otherwise, if it's auto-inc, then likely you could leave off the first argument in the data array so it would just be

$data = array(3, 'Cameron', 'Kirk');

 

Match the argument count.

 

edit: RTFM

DB_ERROR_MISMATCH  mismatch  Quantity of parameters didn't match quantity of placeholders in the prepared statement.  Check that the number of placeholders in the  prepare() statement passed to $query  equals the count of entries passed to $params .
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.