php_phreak_91 Posted June 19, 2007 Share Posted June 19, 2007 Hi I'm new to PHP Freaks. I am trying to use PEAR DB to run a MySQL query but it won't work, I just keep getting DB Error: syntax error. I have checked and the SQL statements run in PHPMyAdmin OK. Here is my code: require_once('../includes/database_connect.php'); $filename = "sql/mysql.sql"; $createTablesQuery = file_get_contents($filename); $res =& $db->query("$createTablesQuery"); if (PEAR::isError($res)){ print $res->getMessage(); } else { print "Tables were created successfully."; } If I enter: print "$createTablesQuery"; Then it prints out the "sql/mysql.sql" file. So why won't PEAR DB run the query. It works in PHPMyAdmin... ??? Quote Link to comment https://forums.phpfreaks.com/topic/56192-pear-db-not-working-properly-get-errors/ Share on other sites More sharing options...
php_phreak_91 Posted June 19, 2007 Author Share Posted June 19, 2007 OK so I changed the code from: if (PEAR::isError($res)){ print $res->getMessage(); } else { To: if (PEAR::isError($res)){ print $res->getUserInfo(); } else { And it stated that there was a syntax error on line 11 of mysql.sql but all that line has on it is: ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; And as far as I can see there is no syntax errors on that line and the whole SQL file works in PHPMyAdmin OK so why not for PEAR DB...??? Quote Link to comment https://forums.phpfreaks.com/topic/56192-pear-db-not-working-properly-get-errors/#findComment-277579 Share on other sites More sharing options...
php_phreak_91 Posted June 19, 2007 Author Share Posted June 19, 2007 Never mind I figured it out eventually: require_once('../includes/database_connect.php'); if ($dbtype == "mysql"){ $filename = "sql/mysql.sql"; } $createTablesFile = @file_get_contents($filename); $createTablesQuery = split(";", $createTablesFile); foreach ($createTablesQuery as $createTables){ $res =& $db->query($createTables); } print "<span class=\"split\">Tables were created successfully.<br /><br /><a href=\"index.php?page=stage3\">Populate tables with default data</a></span>"; Unfortunately no error check but it'll do. lol. Quote Link to comment https://forums.phpfreaks.com/topic/56192-pear-db-not-working-properly-get-errors/#findComment-277597 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.