TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-15-2008, 08:19 PM   #1 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Bug MySQL4 compatible imports into v5...

I'm trying to write an installer script, but when it comes down to the actual "drop if exists" statements it dies on the following line. I have MySQL 5.0.50 and the SQL export (that I'm importing with the script) is in MySQL40 compatibility mode.

Can anyone tell me why a simple statement like the following is dying with the given error? When I import this script by phpMyAdmin, I get to specify MySQL40 compatibility mode though, this whole thing works.

sql Code:
DROP TABLE IF EXISTS `jag_categories`;
CREATE TABLE `jag_categories` (
  `cat_id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT,
  `parent` mediumint(8) UNSIGNED NOT NULL,
  `title` tinytext NOT NULL,
  PRIMARY KEY  (`cat_id`),
  FULLTEXT KEY `title` (`title`)
) TYPE=MyISAM;
Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; CREATE TABLE `jag_categories` ( `cat_id` mediumint(8) unsigned NOT NULL au' at line 20
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-15-2008, 08:54 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

That's a strange one to say the least. The good news is that I can replicate the problem using your export here running MySQL 5.0.45 so I'll play about some more and let you know if I can get it working.

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-15-2008, 09:00 PM   #3 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Okay thanks, it's really a strange one. I'm just doing a "file_get_contents" and running it as my query, in case that method is bad.

Maybe I should format it differently, and do one statement at a time?
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-15-2008, 09:15 PM   #4 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Problem solved - turns out that mysql_query() doesn't support multiple queries (PHP: mysql_query - Manual - "mysql_query() sends an unique query (multiple queries are not supported) to the currently active database..."). The MySQL C API supports a flag to allow multiple queries but I couldn't find one for PHP.

Supposedly some sort of security measure to prevent SQL injection :/

A workaround could be to explode the big query by ';' and run them seperately perhaps.

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-15-2008, 09:17 PM   #5 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

...ugh. I had worried about that. I don't have mysqli available on my server either, which is slightly odd. Thanks for all your help Alan.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-15-2008, 09:20 PM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Before you go about installing mysqli, that doesn't support it either :/

And np's - glad I found this out myself, I'd always assumed it could handle multiple queries.

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-15-2008, 09:40 PM   #7 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

I thought I heard mysqli did! So much for that hope.

Looks like I might have to write my own "multi-query" member for my database. At the moment this work around is successful, though there isn't any aggregation of the results.
PHP Code:
        foreach(explode(";\r\n",$query) as $q) {
          if(!
$q{0}) {
            continue;
          }
          if(
mysql_query($q) == false) {
            
$str mysql_error($pDb).'<br/><tt>'.htmlspecialchars($q).'</tt>';
            if(!empty(
$error) && is_string($error)) {
              
$error = array($error$str);
            } elseif(
is_array($error)) {
              
$error[] = $str;
            } else {
              
$error $str;
            }
          }
        } 
As you can see with a little adaptation you can tweak it for Linux compatibility, but for WAMP it works just fine. For now.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 01-16-2008, 01:08 AM   #8 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
Before you go about installing mysqli, that doesn't support it either :/

And np's - glad I found this out myself, I'd always assumed it could handle multiple queries.
mysqli_multi_query()
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 01-16-2008, 10:16 AM   #9 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Ahh, good call - dammed if I saw that originally

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design