web development
Posted by: Abraham
19 Feb 2009I was setting up a database query using a PDOStatement, by looping through an array of values and binding each parameter seperately. But on executing the query, I got the following error:
Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`places/places`, CONSTRAINT `places_ibfk_3` FOREIGN KEY (`login_id`) REFERENCES `login` (`id`) ON DELETE CASCADE)’ in G:….
Instead of seperately binding each parameter to a variable name with bindParam, as in the following code:
foreach ($columns as $col) {
$stmt->bindParam(":$col", $value);
}
load all the bindings into an associative array, like this:
foreach ($columns as $col) {
$bind[":$col"] = $value;
}
and pass the array to the execute function:
$result = $stmt->execute($bind);
Based in South Africa, we're a web-development company...
(2)
(3)
(1)
(5)
(4)
(1)
(1)
(14)
(1)
(8)
(7)
(17)
(1)
(4)
(2)
(2)
(1)
1 Response to Uncaught PDOException with SQLSTATE[HY000]
neha
October 4th, 2011 at 8:50 am
i was getting pdo exception error when i tried to migrate mysql db to oracle by oracle driver and dbtng migrator.
PDOException: SQLSTATE[HY000]: General error: 904 OCIStmtExecute: ORA-00904: “IDENTIFIER”.”GET_FOR”: invalid identifier (ext\pdo_oci\oci_statement.c:146) in db_table_exists() (line 2730 of C:\wamp\www\usmlerx\includes\database\database.inc).