![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] PHP: Creating tables and timing... HI All I have 2 sets of PHP scripts which I combined to execute at once... - 1...connect to mysql (this is working fine!) - 2...create tables Problems: - when it comes to creating tables (4) only the last one is successfully created and the rest nothing....am i missing something here? - I would like to include a time out in the script....like once the connection is established, it could print out first something like: Please wait creating tables now...! and then proceed immediately with creating tables. The timing could be about 5 seconds of delay....how to do that? here is my script: <?php $link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } $sql = 'CREATE DATABASE test2'; if (mysql_query($sql, $link)) { echo "Database test2 created successfully\n"; } else { echo 'Error creating database: ' . mysql_error() . "\n"; } // Create tables in test2 database mysql_select_db("test2", $link); $sql = "CREATE TABLE car ( title varchar(255) NOT NULL, description varchar(255) NOT NULL, priority tinyint(2) NOT NULL default '0' ) TYPE=InnoDB;\n"; //Create links table $sql = "CREATE TABLE links ( type varchar(20) NOT NULL default '', resource varchar(255) NOT NULL, ) TYPE=InnoDB;\n"; //Create home table $sql = "CREATE TABLE home ( name varchar(255) NOT NULL, title varchar(255) NOT NULL default '', description varchar(255) NOT NULL default '', ) TYPE=InnoDB;\n"; //Create people table $sql = "CREATE TABLE people ( name varchar(20) NOT NULL default '', address varchar(255) NOT NULL resource varchar(255) NOT NULL, ) TYPE=InnoDB;\n"; echo "car,home,links, & people tables in the relational database (".test2.") have been successfully created!\n"; mysql_query($sql, $link); mysql_close($link);//Close connection ?> |
| |
| ||||
| Just a typo. BTW: line numbers matter, so if your system outputs them it's a great help to helping you. PHP Code: |
| The Following User Says Thank You to TeraTask For This Useful Post: | ||
HelloWorld (08-17-2007) | ||
| |||
| It would be more efficient to concatenate SQL queries and only make one call to the DB. Instead of $sql = "whatever";, use PHP Code: Notice the period (.) before the equals sign (.=). Also! Make double-sure that your queries are complete! Since they are being concatenated, you'll have to make sure to end each query with ';'. |
| ||||
| That's useful there's transaction... probably it shouldn't really matter in this case..? ![]() |
| The Following User Says Thank You to HelloWorld For This Useful Post: | ||
TeraTask (08-23-2007) | ||
| |||
| Quote:
For one time uses such as creating these tables, it probably won't matter. It's a good habit to get into though. |
![]() |
| Thread Tools | |
| Display Modes | |
| |