Hello,
I'm using the script below to insert "trigger" records into a table.
Existence of such record prevents the server from running redundant activity somewhere else.
$sqlCalcStatus2 = $modx->db->query("SELECT 1 FROM `cg_celeb_calculation_status` WHERE (CelebID = '$CelebID')");
$resultCalcStatus2 = $modx->db->getRow($sqlCalcStatus2);
if (!$resultCalcStatus2)
{
$fields = array('CelebID' => $CelebID);
$modx->db->insert( $fields, 'cg_celeb_calculation_status' );
}
However, I'm getting occasional and inconsistent error messages from MODx about an attempt to insert duplicate CelebID value:
« MODX Parse Error »
MODX encountered the following error while attempting to parse the requested resource:
« Execution of a query to the database failed - Duplicate entry '328887' for key 'PRIMARY' »
SQL > INSERT INTO cg_celeb_calculation_status (`CelebID`) VALUES('328887')
Can someone propose a better mean to avoid insert if record already exists?
Thanks a lot,
Shlomo
[ed. note: shlomot last edited this post 11 years, 10 months ago.]