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.

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 .

Archived

This topic is now archived and is closed to further replies.

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