Executing SQL Syntax

Torch

New Member
Messages
634
Reaction score
0
Points
0
PHP:
<?
mysql_query(file_get_contents("query.sql"));
?>
 

Torch

New Member
Messages
634
Reaction score
0
Points
0
PHP:
<? 
$conn = mysql_connect("localhost","username","password");
mysql_select_db("database",$conn);
mysql_query(file_get_contents("query.sql")); 
?>
If that is what you meant.
 

the_king_dollars

New Member
Messages
153
Reaction score
0
Points
0
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.
 

Torch

New Member
Messages
634
Reaction score
0
Points
0
Ok, there are many ways you can do it, but I'll elaborate the script I made you.

PHP:
$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:
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:
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 :)
 

the_king_dollars

New Member
Messages
153
Reaction score
0
Points
0
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.
 
Top