pquery Posted July 14, 2009 Share Posted July 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165993-posting-to-autoincrement-field-in-mysql-database-using-pear-db-execute-insert/ Share on other sites More sharing options...
xtopolis Posted July 15, 2009 Share Posted July 15, 2009 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 . Quote Link to comment https://forums.phpfreaks.com/topic/165993-posting-to-autoincrement-field-in-mysql-database-using-pear-db-execute-insert/#findComment-875532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.