I am trying to update the intro field of the content DB (Joomla) with a whole HTML code which is about 1200 lines long.
try {
$MyDBConn = new PDO("mysql:host=localhost;port=3306;dbname=$MyDBName", $MyDBUser, $MyDBPass);
// PDO can throw exceptions rather than Fatal errors, so let's change the error mode to exception
$MyDBConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$MySQL = "UPDATE jso_content SET introtext = '$MyTeamHTML_FR' WHERE titel like '%$MyTeamTitel' and alias like '%$MyTeamAlias'";
$MySQL = "UPDATE jso_content SET introtext = :INTRO WHERE alias = :ALIAS";
$MyStmt = $MyDBConn->prepare($MySQL);
$MyStmt->execute(array(':INTRO' => $MyTeamHTML_FR, ':ALIAS' => $MyTeamAlias));
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage()."\n";
}
$MyDBConn = null;
The update does not perform tough and I don't know why. When I do this manually through PHPMyAdmin, I can insert the text code.
I used the same statements in a post before and this got solved as there was an error while using exec() instead of execute().
Another comment was on SQL injection attacks, which I hope I solved.
Thank you for your support
Regards
Laurent
I change your code a little and added code for logging the exception. This will help you debug in case of error and solve it.
try {
$MyDBConn = new PDO("mysql:host=localhost;port=3306;dbname=$MyDBName", $MyDBUser, $MyDBPass);
// PDO can throw exceptions rather than Fatal errors, so let's change the error mode to exception
$MyDBConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$MySQL = "UPDATE jso_content SET introtext = '$MyTeamHTML_FR' WHERE titel like '%$MyTeamTitel' and alias like '%$MyTeamAlias'";
$MySQL = "UPDATE jso_content SET introtext = :INTRO WHERE alias = :ALIAS";
$MyStmt = $MyDBConn->prepare($MySQL);
$MyStmt->execute(array(':INTRO' => $MyTeamHTML_FR, ':ALIAS' => $MyTeamAlias));
}
catch(PDOException $e) {
$h = fopen('<path_to_a_writable_dir>/error.log', 'a+');
fwrite($h, var_export($e, true));
echo "Connection failed: " . $e->getMessage()."\n";
}
$MyDBConn = null;
Make sure to pass writable dir for path_to_a_writable_dir
Sorry for that post. I realized later last might, that I had a typo here in
"UPDATE jso_content SET introtext = :INTRO WHERE alias = :ALIAS"
this should bw
"UPDATE jos_content SET introtext = :INTRO WHERE alias = :ALIAS"
After changing it, the scripts passed.
Anyway, thank you for your comments Cheers Laurent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.