cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Help

N/A

SQL Help

Ive been using the following sql that works fine from within phpmyadmin sql panel but I cant seem to use from php. Basically the sql removes dupes form a table.
Could someone point out whats wrong!
cheers

SQL works

CREATE TABLE `site_rss_tmp` (
`id` int(10) NOT NULL auto_increment,
`section` varchar(128) NOT NULL default '',
`pubDate` varchar(64) NOT NULL default '',
`url` varchar(255) NOT NULL default '',
`link` varchar(255) NOT NULL default '',
`description` mediumtext NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

INSERT INTO site_rss_tmp(section,pubDate,url,link,description) SELECT DISTINCT section,pubDate,url,link,description FROM site_rss;

DELETE FROM site_rss;

INSERT INTO site_rss(id,section,pubDate,url,link,description) SELECT id,section,pubDate,url,link,description FROM site_rss_tmp;

DROP TABLE site_rss_tmp;




PHP doesnt
<?php

{removed}

mysql_connect($host,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = 'CREATE TABLE `site_rss_tmp` ('
. ' `id` int(10) NOT NULL auto_increment,'
. ' `section` varchar(128) NOT NULL default \'\','
. ' `pubDate` varchar(64) NOT NULL default \'\','
. ' `url` varchar(255) NOT NULL default \'\','
. ' `link` varchar(255) NOT NULL default \'\','
. ' `description` mediumtext NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ' ) TYPE=MyISAM;'
. ' INSERT INTO site_rss_tmp(section,pubDate,url,link,description) SELECT DISTINCT section,pubDate,url,link,description FROM site_rss;'
. ' DELETE FROM site_rss;'
. ' INSERT INTO site_rss(id,section,pubDate,url,link,description) SELECT id,section,pubDate,url,link,description FROM site_rss_tmp;'
. ' DROP TABLE site_rss_tmp;'
. ' ';

mysql_query($query);

mysql_close();
?>
2 REPLIES
prichardson
Grafter
Posts: 1,503
Registered: 05-04-2007

SQL Help

Hi,

You will need to run multiple mysql_query() calls, for each SQL call to be performed.

The PHP documentation does not make it clear, as only one SQL call can be made per function call. This is a security feature, and will help negate many SQL injection security problems in your code, though not all.

http://uk.php.net/mysql-query

Kind Regards,
N/A

SQL Help

I would never have thought that
Thanks for the help