1

I'm in need of inserting a control query into a hook post to retrieve if there is duplicate data.

I am using a php query but the only reaction I have is that it continues to compute forever, is it possible that there are strings of CIVI seasoning more suitable for this task?

$check = mysql_query("SELECT * FROM table WHERE code = '$invoicenum'");
    $checkrows = mysql_num_rows($check);

   if ($checkrows > 0) {
WARNING
   } 
   else {
OK CONTINUE CHANGE
}

Regards

1

You're using mysql_query, which is deprecated in both PHP and modern versions of Civi. The code isn't running forever, it's failed with an error - you should be able to find that error, most likely in your CiviCRM log.

While you could use mysqli_query, the better choice is to use a wrapper, which should give at least partial future-proofing. Here's my (untested!) attempt at a rewrite:

Use:

$check = CRM_Core_DAO::executeQuery("SELECT * FROM table WHERE code = '$invoicenum'");

if ($check->fetch()) {
  // WARNING
else
  // OK
}

Note also that if you're using the post hook, the data has already been written to the database. I would put this in a validation hook or an API Wrapper hook if you're trying to prevent the data being written.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.