944,047 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 378
  • PHP RSS
Oct 15th, 2009
0

Confused :(

Expand Post »
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)
  1.  
  2. <?php
  3. DEFINE ('DB_USER', 'USERNAME');
  4. DEFINE ('DB_PASSWORD', 'PASSWORD');
  5. DEFINE ('DB_HOST', 'localhost');
  6. DEFINE ('DB_NAME', 'TABLE');
  7.  
  8. // make the connection
  9. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('');
  10.  
  11. // select the database
  12. $tbc = @mysql_select_db (DB_NAME) OR die ('fgddffdfdfd');
  13.  
  14. if(!$tbc)
  15. {
  16. sql_insert();
  17. }else{
  18. }
  19.  
  20. ?>

Thanks for any help
Similar Threads
Reputation Points: 41
Solved Threads: 7
Posting Whiz in Training
Phil++ is offline Offline
233 posts
since Jan 2009
Oct 15th, 2009
1
Re: Confused :(
This should work...

PHP Syntax (Toggle Plain Text)
  1. mysql_query("CREATE TABLE IF NOT EXISTS `table_name` (
  2. `field_name` int(11) NOT NULL AUTO_INCREMENT,
  3. `field_name` varchar(65),
  4. ...,
  5. ...,
  6. ...,
  7. PRIMARY KEY (`field_name`)
  8. )");
Last edited by Will Gresham; Oct 15th, 2009 at 9:00 pm.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Oct 16th, 2009
-1
Re: Confused :(
Click to Expand / Collapse  Quote originally posted by Phil++ ...
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)
  1.  
  2. <?php
  3. DEFINE ('DB_USER', 'USERNAME');
  4. DEFINE ('DB_PASSWORD', 'PASSWORD');
  5. DEFINE ('DB_HOST', 'localhost');
  6. DEFINE ('DB_NAME', 'TABLE');
  7.  
  8. // make the connection
  9. $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('');
  10.  
  11. // select the database
  12. $tbc = @mysql_select_db (DB_NAME) OR die ('fgddffdfdfd');
  13.  
  14. if(!$tbc)
  15. {
  16. sql_insert();
  17. }else{
  18. }
  19.  
  20. ?>

Thanks for any help

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //check table
  3. function checktable($tablename){
  4. return mysql_query("select * from ".$tablename." limit 0,1");
  5. }
  6.  
  7. $table="table_name_that_want_to_be_check";
  8. if(checktable($table)){
  9. echo"table already created";
  10. }else{
  11. //create table if not exist
  12. mysql_query("CREATE TABLE ".$table." (
  13. id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  14. data VARCHAR(100),
  15. ......................
  16. );")
  17. echo "table created"
  18. }
  19.  
  20. ?>
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Uploading files to web server...
Next Thread in PHP Forum Timeline: PHP & Apache Server Security Questions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC