Posted By

DrPepper on 05/01/11


Tagged


Versions (?)

PHP with mySQL


 / Published in: MySQL
 

Basic mySQL code with php file kind of memo stuff

  1. <?php
  2. //Connect to your database server *portNum IS OPTION
  3. $contents = mysql_connect("hostName:portNum","mySQL_userName","mySQL_password");
  4. if(!$contents)
  5. {
  6. die("cant open the sql file ".mysql_error());
  7. }
  8.  
  9. // SELECT database
  10.  
  11. mysql_select_db("dataBaseName", $contents);
  12.  
  13. //CREATE TABLE
  14.  
  15. $sql = "CREATE TABLE tableName
  16. (
  17. FirstName varchar(15), //15 is max roll
  18. LastName varchar(15),
  19. Age int
  20. )";
  21.  
  22. // INSERT Data INTO your database table
  23.  
  24. mysql_query("INSERT INTO tableName(FirstName, LastName, Age) VALUES('adam', 'Griffin', '35')");
  25.  
  26. //UPDATE database
  27.  
  28. mysql_query("UPDATE tableName SET age='40' WHERE FirstName='adam' AND LastName='Griffin'");
  29.  
  30. //DELETE database
  31.  
  32. mysql_query("DELETE FROM tableName WHERE FirstName='adam'");
  33.  
  34. // WHERE : location it's feeling like seekg() and tellp() with C++
  35. // ORDER BY : you can change the order by whatever you want
  36.  
  37. ?>

Report this snippet  

You need to login to post a comment.