Jump to content

Recommended Posts

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...  ???

Link to comment
https://forums.phpfreaks.com/topic/56192-pear-db-not-working-properly-get-errors/
Share on other sites

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...???

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.  ;D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.