| | |
Confused :(
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
Posts: 151
Reputation:
Solved Threads: 3
Hey, I'm working on a College project that means you have to re-do the database each time you work on your assignment. So, what I'm hoping to create is a file called "sql_connect.php" which will check if the table is there, if not.. It will run the function that creates it. Here is my code:
Thanks for any help
PHP Syntax (Toggle Plain Text)
<?php DEFINE ('DB_USER', 'USERNAME'); DEFINE ('DB_PASSWORD', 'PASSWORD'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'TABLE'); // make the connection $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die (''); // select the database $tbc = @mysql_select_db (DB_NAME) OR die ('fgddffdfdfd'); if(!$tbc) { sql_insert(); }else{ } ?>
Thanks for any help
1
#2 Oct 15th, 2009
This should work...
PHP Syntax (Toggle Plain Text)
mysql_query("CREATE TABLE IF NOT EXISTS `table_name` ( `field_name` int(11) NOT NULL AUTO_INCREMENT, `field_name` varchar(65), ..., ..., ..., PRIMARY KEY (`field_name`) )");
Last edited by Will Gresham; Oct 15th, 2009 at 9:00 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Mar 2008
Posts: 70
Reputation:
Solved Threads: 1
-1
#3 Oct 16th, 2009
•
•
•
•
Hey, I'm working on a College project that means you have to re-do the database each time you work on your assignment. So, what I'm hoping to create is a file called "sql_connect.php" which will check if the table is there, if not.. It will run the function that creates it. Here is my code:
PHP Syntax (Toggle Plain Text)
<?php DEFINE ('DB_USER', 'USERNAME'); DEFINE ('DB_PASSWORD', 'PASSWORD'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'TABLE'); // make the connection $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die (''); // select the database $tbc = @mysql_select_db (DB_NAME) OR die ('fgddffdfdfd'); if(!$tbc) { sql_insert(); }else{ } ?>
Thanks for any help
PHP Syntax (Toggle Plain Text)
<?php //check table function checktable($tablename){ return mysql_query("select * from ".$tablename." limit 0,1"); } $table="table_name_that_want_to_be_check"; if(checktable($table)){ echo"table already created"; }else{ //create table if not exist mysql_query("CREATE TABLE ".$table." ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, data VARCHAR(100), ...................... );") echo "table created" } ?>
http://www.duniaislam.site50.net
Others Social Bookmarking http://www.bisnis-indonesia.org
Business Web Directory
http://www.bisnis-indonesia.biz
Others Social Bookmarking http://www.bisnis-indonesia.org
Business Web Directory
http://www.bisnis-indonesia.biz
![]() |
Similar Threads
- confused about SE + SEO. (Search Engine Optimization)
- Confused about SATA RAID (Storage)
- Confused about loops and switch (Java)
- Confused writing a Java Class (Java)
- confused about shell sort ... (C)
- confused how to begin this program (C++)
- Need help With this C++ Program..Confused.. (C++)
- ftp client issues...im so confused...plz help!!! (Windows Software)
Other Threads in the PHP Forum
- Previous Thread: Uploading files to web server...
- Next Thread: PHP & Apache Server Security Questions
| Thread Tools | Search this Thread |
.htaccess ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl customizableitems database date delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube





