#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Currently Poland, sometimes London, originally Wales . . .
    Posts
    154
    Rep Power
    15

    MySQL "source" command in PHP


    As part of a feature to backup and recover database content. I'm trying to use the mySQL "source" command through PHP.

    I know some people will be thinking "but this is a database question - why is it being posted to the PHP forum?"

    Well, the problem is that the relevant mySQL query runs perfectly well from the mySQL command prompt but fails when run through mysql_query().

    Let me explain in a bit more detail . . .

    From the mySQL command line, the following command will run all queries within the specified file:

    Code:
    source filename
    Therefore, within PHP, I tried the following (with a known-to-exist filename):

    PHP Code:
    mysql_query("source FI_autocap.sql"); 
    This didn't work and for some time I thought that I needed to specify the exact path to the file to be sourced. I tried many things to no avail.

    Then my brain started working and I looked at the error returned from:

    PHP Code:
    $s_source_sql="source FI_autocap.sql";

    if (
    mysql_query($s_source_sql))            
    {
        print(
    "file sourced");            
    }
    else
    {
        print(
    mysql_error());    

    which was:

    Code:
    You have an error in your SQL syntax near 'source FI_autocap' at line 1
    I know that there is no syntax error in the SQL query since "source FI_autocap.sql" as this works fine from the mySQL command line.

    I understand that mysql_query() can only run one SQL query at a time and I don't reckon that this will be a problem as I am only trying to run one query (although the SQL query I am trying to run does then perform loads of queries, which is why I considered this).

    So, my questions are:

    1. Has anyone tried using the mySQL source command within a query run my mysql_query() before and if so, did it work and how?

    2. Is the mysql_query() function in PHP limited to what types of queries it can run? I see nothing in the PHP manual on mysql_query() stating that it cannot do certain things.

    3. Has anyone tried to recover the contents of a database or database table through PHP where the database or table has been backed-up with the mysqldump command and if so, how?

    I know this is a bit of a long thread-starter, but I'm just trying to be as clear and precise as possible

    Thanks for any help that can be offered !

    --
    CW
  2. #2
  3. No Profile Picture
    contains a pressurised widget
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    NC USA
    Posts
    401
    Rep Power
    15
    Error in using "source" command with PHP USENET post

    According to the above post that I found through google, and confirmed by other sites I came across.. SOURCE is a MySQL client command, and not a SQL command. I'm not going to copy somebody else's post. so if yuo follow the link you'll see what their work-around is.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Currently Poland, sometimes London, originally Wales . . .
    Posts
    154
    Rep Power
    15
    Cheers c444l - thanks for the info!

    Just goes to show how poor my google searching is

    I'll have a look at the link and see what can be done.

    Thanks again

IMN logo majestic logo threadwatch logo seochat tools logo