Might be a beginner question...

    Date: 04/25/06 (PHP Community)    Keywords: php, mysql, sql

    Solved:see bottom of post for more info.

    I have a .sql file that has 3 commands in it.
    2 "Create Tables table' followed by a "Insert Into table"

    Each command is terminated with a ;

    If I copy the text directly into MySQL. no problems.

    I'm trying to get a php file to run the information in the page.

    Below the cut is what I tried, what happened, and what I realized:

    I tried:

    echo "Creating tables and data for $sql_file_name...";
    $str = file_get_contents($filePath . $sql_file_name);
    if (mysql_query($str)) {
    	echo " Done.
    \n"; } else { echo mysql_errno() . ": Error on query for sqlfile $sql_file_name: " . mysql_error() . "
    \n"; die; }
    The runtime came back with
    1064: Error on querry for sqlfile address.sql:
    You have an error in your SQL syntax;
    check the manual that corresponds to your MySQL server version for
    the right syntax to use near ';
    CREATE TABLE `Address_Type`
    ( `AddType_UID` int(50) NOT NULL auto_increment' at line 15
    My guess is that since PHP queries are submitted without a semi-colon that this tripped up the system. So my question:

    Is there a php command: Run_sql_in_file($filepath) ... or
    Is there a way to split my .sql string that I'm getting from file_get_contents() into an array split by the semicolon character?

    If not obvious I am quite new to PHP and pretty much self teaching as I go.

    Thanks!

    SOLVED:

    I found the explode() command. '[info]'zimzat posted at about the same time.

    I'm on the way out, but will post the final function I generated later if people are interested.

    Source: http://community.livejournal.com/php/444038.html

« include with variables || creating variable »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home