knox203 Posted September 5, 2008 Share Posted September 5, 2008 Hello all! I have a little block of code I wrote to open a .sql file, replace a word in the sql file, then by using output buffering, create a table in a MySQL database. I keep getting a MySQL error returned saying "You have an error in your SQL syntax". Can anyone tell me if something looks blatantly wrong?? Thanks! <?php ob_start(); $file = "temp/test.sql"; $file_open = fopen($file, 'r+') or die("Can't Open File!!"); do { $line = fgets($file_open, filesize($file)); $line = str_replace("UPDATE", "UPDATE_DATE", $line); print $line; } while (!feof($file_open)); fclose($file_open); $create_select = ob_get_contents(); ob_clean(); $host = "sql1"; $username = "test"; $password = "test"; $db_name = "test"; mysql_connect("$host", "$username", "$password") or die("cannot connect"); mysql_select_db("$db_name") or die("cannot select DB"); mysql_query($create_select) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/122801-using-output-buffering-to-create-a-table/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 5, 2008 Share Posted September 5, 2008 Using output buffering not necessary. Just concatenate each $line onto a variable (such as $content). For us to have any chance at helping your with your error, you are going to need to post it along with echoing $create_select to see what it contains. Link to comment https://forums.phpfreaks.com/topic/122801-using-output-buffering-to-create-a-table/#findComment-634150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.