PHP 5.4.7 in xampp installation, MySQL 5.5.27 - I have struggled all day to get various UPDATE statements to work, to no avail. Have read through and tried examples from http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers, and have given up on one UPDATE (found an alternative solution) but am going nuts wondering what is wrong with THIS one, below. Btw all my other PDO FETCHALL queries work fine ...
function updateThisMemberInterests($PDOdbObject, $memberId, $interests)
{
try
{
$intId = 0;
$upInt = $connectionObject->prepare("UPDATE `member_interest` SET (`interest_id`) VALUES (:intId)");
$upInt->bindParam(':intId', $intId, PDO::PARAM_INT);
foreach($interests as $intId)
{
$upInt->execute();
}
$affected_rows = $upInt->rowCount();
return $affected_rows;
}
catch (PDOException $e)
{
echo "There was a problem connecting to this database.";
$e->getMessage();
}
}
My database setup function specifies: PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
but I'm not getting anything except my echoed message in the Catch.
Must have interpreted the tutorial's instructions wrongly - can someone tell me what it is?
rowCount()
only applies to the most recentexecute()
, so calling it after your loop won't give you correct information. – Michael Berkowski$PDOdbObject
, but you call$connectionObject
in the function body. Turn onerror_reporting
anddisplay_errors
, and you'll see call to a member function prepare() on a non object. – Michael Berkowskiecho $e->getMessge();
– Michael Berkowski