How is this query “invalid syntax”?
[code]
CREATE TABLE `test_test` (
`id` int(4) NOT NULL auto_increment,
`link` varchar(16) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;
INSERT INTO `test_test` VALUES (2, ‘Legal_Forms’);
INSERT INTO `test_test` VALUES (1, ‘E-Mail_Order’);
INSERT INTO `test_test` VALUES (3, ‘Templates’);
It was created with phpMyAdmin’s export feature, it can’t have a syntax error. I’m running the query with this PEAR?B-based script:
[code=php]
<?php
require(“db_connect.php”);
if(empty($_POST[‘query’])){
print “<form action=””.$_SERVER[‘PHP_SELF’].”” method=”post”>n<div align=”center”><textarea name=”query” rows=”15″ cols=”60″>n”;
?>
CREATE TABLE `test_test` (
`id` int(4) NOT NULL auto_increment,
`link` varchar(16) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;
INSERT INTO `test_test` VALUES (2, ‘Legal_Forms’);
INSERT INTO `test_test` VALUES (1, ‘E-Mail_Order’);
INSERT INTO `test_test` VALUES (3, ‘Templates’);
<?php
print “</textarea><br/>n<input type=”submit” /></div>n</form>n”;
}else{
//POST data is present
if(!get_magic_quotes_gpc()){
$_POST[‘query’]=addslashes($_POST[‘query’]);
}
$customQuery=$db_object->query($_POST[‘query’]);
if(!DB::isError($customQuery)){
print “<h3 align=”center”>Query successful!</h3>n”;
print “<table align=”center” width=”60%” border=”0″><tr><td>n”;
print “<pre>”;
echo htmlspecialchars(stripslashes($_POST[‘query’]));
print “</pre>n”;
print “</td></tr></table>n”;
}else{
print “<h3 align=”center”>Could not execute the query!</h3>n”;
print “<table align=”center” width=”60%” border=”0″><tr><td>n”;
print “Database error or bad SQL query:<br/>n”;
print $customQuery->getMessage().”<br>n”;
print “<pre>”;
echo htmlspecialchars(stripslashes($_POST[‘query’]));
print “</pre>n”;
print “</td></tr></table>n”;
}//end if query success
print “<br/><div align=”center”><input type=”button” value=”Go Back” onClick=”window.location.href='”.$_SERVER[‘PHP_SELF’].”‘;” /></div>n”;
}//end if POST data
?>
And it keeps coming back with DB::isError($customQuery) being true, not writing to the db, and the only error message is: “DB Error: syntax error”. You can get useful data back if you change the query to “SELECT * FROM test_users ORDER BY id”, but not even all SELECT statements work. “SELECT username FROM `test_users
Complicated, I know, but I’ve got to get something that will read the contents of a SQL dump into a SQL query to recreate the database, and WORK.
P.S. Just a thought, does PEAR require only one SQL statement per query? I got a working model with a couple of different queries [url=http://gaston9x19.modcentral.us/test/testSQL.php]here