+ Reply to Thread
Results 1 to 7 of 7

Thread: Executing SQL Syntax

  1. #1
    the_king_dollars's Avatar
    the_king_dollars is offline x10 Sophmore the_king_dollars is an unknown quantity at this point
    Join Date
    Nov 2006
    Posts
    153

    Question Executing SQL Syntax

    How can I execute SQL files such as .sql?

  2. #2
    Torch's Avatar
    Torch is offline x10 Lieutenant Torch is an unknown quantity at this point
    Join Date
    Apr 2006
    Location
    Belgrade, Serbia
    Posts
    317

    Re: Executing SQL Syntax

    PHP Code:
    <?
    mysql_query
    (file_get_contents("query.sql"));
    ?>

  3. #3
    the_king_dollars's Avatar
    the_king_dollars is offline x10 Sophmore the_king_dollars is an unknown quantity at this point
    Join Date
    Nov 2006
    Posts
    153

    Re: Executing SQL Syntax

    How do I add the name of the database, username and password?
    Last edited by the_king_dollars; 12-07-2006 at 05:28 AM.

  4. #4
    Torch's Avatar
    Torch is offline x10 Lieutenant Torch is an unknown quantity at this point
    Join Date
    Apr 2006
    Location
    Belgrade, Serbia
    Posts
    317

    Re: Executing SQL Syntax

    PHP Code:
    <? 
    $conn 
    mysql_connect("localhost","username","password");
    mysql_select_db("database",$conn);
    mysql_query(file_get_contents("query.sql")); 
    ?>
    If that is what you meant.

  5. #5
    the_king_dollars's Avatar
    the_king_dollars is offline x10 Sophmore the_king_dollars is an unknown quantity at this point
    Join Date
    Nov 2006
    Posts
    153

    Re: Executing SQL Syntax

    Yes that is what I meant. Thank you for your support.
    But I tried it and it doesn't work. What I did is that I put the code into script.php . The code has my details in it. While it didn't inform me of problems no tables were added.
    So how do I execute .sql?
    Please step by step.

  6. #6
    Torch's Avatar
    Torch is offline x10 Lieutenant Torch is an unknown quantity at this point
    Join Date
    Apr 2006
    Location
    Belgrade, Serbia
    Posts
    317

    Re: Executing SQL Syntax

    Ok, there are many ways you can do it, but I'll elaborate the script I made you.

    PHP Code:
    $conn mysql_connect("localhost","username","password"); 
    That line is used to connect to your database server. The first argument (localhost in this example) is the IP or URI address of the server. The second is the username, and third password. The function is stored into $conn variable so we could use it more easily later.
    PHP Code:
    mysql_select_db("database",$conn); 
    That function is used to select a database to which queries will be sent. First agument is name of the databse. The second argument (in this case $conn) is mysql connection link identifier (connection to server).
    PHP Code:
    mysql_query(file_get_contents("query.sql")); 
    This line consists of 2 function. file_get_contents is used to read contents of a file and store it in a string. The first argument in it (and only in this case) is the path to your file. To make it easier you should put your .sql file in same directory as this script. Also make sure that SQL synthax in your sql file is correct and valid.
    mysql_query function is used to send a query to database which has been selected by functions in 2 lines above. It's argument is query string, and in this case the string is fetched from your sql file via file_get_contents.

    There isn't that much to make it more "steppy" so just make sure that you enter correct details where needed and it will work as intended

  7. #7
    the_king_dollars's Avatar
    the_king_dollars is offline x10 Sophmore the_king_dollars is an unknown quantity at this point
    Join Date
    Nov 2006
    Posts
    153

    Re: Executing SQL Syntax

    I did exactly what you said but no table was added. Maybe the problem is with the SQL syntax.
    Anyway, can you please create a file for me to download and run?
    If you will here is my details:
    DB Username: tkd_arcade
    DB Name: tkd_allother
    DB Password: *****
    As for the password, just type *****.
    Thank you.

+ Reply to Thread

Similar Threads

  1. about SQL syntax error..
    By tychicus in forum Off Topic
    Replies: 3
    Last Post: 10-03-2006, 10:08 AM
  2. i last my sql data
    By sahil3x1 in forum Free Hosting
    Replies: 2
    Last Post: 08-28-2006, 06:31 AM
  3. Replies: 6
    Last Post: 07-24-2006, 06:39 AM
  4. SQL Help
    By Shadow in forum Free Hosting
    Replies: 11
    Last Post: 04-04-2005, 01:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers