Confused :(

Reply

Join Date: Jan 2009
Posts: 151
Reputation: Phil++ is an unknown quantity at this point 
Solved Threads: 3
Phil++ Phil++ is offline Offline
Junior Poster

Confused :(

 
0
  #1
Oct 15th, 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:

  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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
1
  #2
Oct 15th, 2009
This should work...

  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.
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 70
Reputation: forzadraco is an unknown quantity at this point 
Solved Threads: 1
forzadraco forzadraco is offline Offline
Junior Poster in Training
 
-1
  #3
Oct 16th, 2009
Originally Posted by Phil++ View 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:

  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

  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. ?>
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 196 | Replies: 2
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC