I'm doing around 600 INSERT ON DUPLICATE KEY UPDATE queries where each insert can have a different set of columns.
The way i'm doing it now is just a foreach loop with a mysql_query(). It's really slow, the php script stops due to maximum execution time of 30s.
I cant use INSERT INTO table (columns) VALUES (values 1), (values 2), ..., (values n) because each insert must be able to have a different set of columns.
I also looked at prepared queries but from what i saw it seems like that won't work with different column sets either.
I'm quite a novice to databases and MYSQL. I'm just hacking together something as a weekend project, and right now i just want to get this last piece of the project to work. I'm sorry about not doing this the proper way. (sorry about using deprecated php mysql functions too.) Maybe i should go to bed and rewrite this later. What would be the proper way to do it?
EDIT: here is some info on the table type
-- phpMyAdmin SQL Dump -- version 3.5.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Jul 22, 2012 at 09:59 PM -- Server version: 5.5.24-log -- PHP Version: 5.3.13 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; -- -- Database: `trailerbay` -- -- -------------------------------------------------------- -- -- Table structure for table `movies` -- CREATE TABLE IF NOT EXISTS `movies` ( `id` int(11) NOT NULL AUTO_INCREMENT, `imdb` int(7) NOT NULL, `title` text COLLATE utf8_unicode_ci, `releasedate` date DEFAULT NULL, `enlistdate` datetime NOT NULL, `runtime` time DEFAULT NULL, `trailer` text COLLATE utf8_unicode_ci NOT NULL, `plot` text COLLATE utf8_unicode_ci, `cover` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), UNIQUE KEY `imdb` (`imdb`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1145 ;
mysqlmodule for PHP for new code. In fact, don't use it for any code if you can help it; it lacks support for parameter interpolation which makes it easy to create SQL injection vulnerabilities. Consider switching to at leastmysqliinstead. - millimoose