title: how can I check foreign key constrain on delete restrict using PHP
body: <p>I have two tables <b>Product</b> and <b>purchase</b>. 
  I set a <code>on delete restrict</code> FK in <code>product.purchase_id</code> column with <code>purchase.purchase_id</code> column. Then  if I try to delete product.product_id with FK, It shows error just like</p>
  
  <pre>
  A Database Error Occurred
  
  Error Number: 1451
  
  Cannot delete or update a parent row: a foreign key constraint fails (`another_bata`.`product_purchase_item`, CONSTRAINT `FK_product_purchase_item_1` FOREIGN KEY (`product_id`) REFERENCES `product` (`product_id`) ON UPDATE CASCADE)
  
  delete from product where product_id='158'
  
  Filename: C:\xampp\htdocs\rima_shoe\system\database\DB_driver.php
  
  Line Number: 330
  
  </pre>
  
  <blockquote>
    <p>But I need a user friendly error suppose <b>You cant Remove this product
    list, Beause you have already stock this product</b></p>
  </blockquote>
  
  <p>So I need to check this FK in php , How can I do this?</p>
  
  <p>My second question.. Is it possible to delete a 'product.product_id' which already exist <code>on delete restrict</code> FK in some special case? suppose</p>
  
  <pre><code>DELETE p,q FROM product AS p INNER JOIN purchase AS q
  WHERE p.purchase_id=q.purchase_id AND q.purchase_quan=0
  </code></pre>