Jump to content

Using Output Buffering to create a table


knox203

Recommended Posts

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());
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.