Answers.Body: <p>You're using <code>mysql_query</code>, 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.  </p>
  
  <p>While you could use <code>mysqli_query</code>, the better choice is to use a wrapper, which should give at least partial future-proofing.  Here's my (untested!) attempt at a rewrite:</p>
  
  <p>Use:</p>
  
  
  
  <pre><code>$check = CRM_Core_DAO::executeQuery("SELECT * FROM table WHERE code = '$invoicenum'");
  
  if ($check-&gt;fetch()) {
    // WARNING
  else
    // OK
  }
  </code></pre>
  
  <p>Note also that if you're using the <em>post</em> 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-20T19:02:13.620Z
Answers.LastActivityDate: 2020-03-20T19:02:13.620Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I'm in need of inserting a control query into a hook post to retrieve if there is duplicate data. </p>
  
  <p>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?</p>
  
  <pre><code>$check = mysql_query("SELECT * FROM table WHERE code = '$invoicenum'");
      $checkrows = mysql_num_rows($check);
  
     if ($checkrows &gt; 0) {
  WARNING
     } 
     else {
  OK CONTINUE CHANGE
  }
  </code></pre>
  
  <p>Regards</p>
  
Tags: <hooks>
Title: Control duplicate entries in Hook Post
ThreadText: # Control duplicate entries in Hook Post
  
  (Asked by: username_0 on 2020-03-20)
  
  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
  
  **Tags:** hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-20. Score: 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.
  
  
  ---
  
  