Ignore Key Constraints - PHP

In one of my scripts I have to do a mass upload of inserts, updates and deletes to a innoDB database. If I do not process these files in a proper table order, I will get a key constraint error. A solution to get around this is to simply run this code before you run your insert, update or delete statement.

// make sure you have already established a connection to a database... then:
$sql_key = 'SET FOREIGN_KEY_CHECKS=0';
mysql_query($sql_key) or die('Could not Insert values: '.mysql_error());
 
 
// then run your insert statement

I use this code because I get my table list from file names on a FTP server. This comes to me in alphabetic order, which is obviously not the proper table order. So when I automate the inserts it inserts in the FTP list order and will throw errors.

This isn't the greatest solution since you may end up with some corrupted indexes if the data isn't perfect when you receive it. But if you cannot find another solution, this will work. Just make sure the data you receive is clean!

 
development/sql/ignore_key_constraints.txt · Last modified: 2007/09/14 14:32 by vincenzobar
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki