Free download web templates, books and more. Free php projects ,games and apps. GTA mods and more

Breaking

php mysql create table || how to Create php mysql table

MySQL Create Table

PHP mysql_query() function is used to create table. Since PHP 5.5, mysql_query() function is deprecated. Now it is recommended to use one of the 2 alternatives.
  • mysqli_query()

PHP MySQLi Create Table Example

Example
  1. <?php  
  2. $host = 'localhost';  
  3. $user = '';  
  4. $pass = '';  
  5. $dbname = 'test';  
  6.   
  7. $conn = mysqli_connect($host$user$pass,$dbname);  
  8. if(!$conn){  
  9.   die('Could not connect: '.mysqli_connect_error());  
  10. }  
  11. echo 'Connected successfully<br/>';  
  12.   
  13. $sql = "create table student(id INT AUTO_INCREMENT,name VARCHAR(20) NOT NULL,  
  14. emp_salary INT NOT NULL,primary key (id))";  
  15. if(mysqli_query($conn$sql)){  
  16.  echo "Table student created successfully";  
  17. }else{  
  18. echo "Could not create table: ". mysqli_error($conn);  
  19. }  
  20.   
  21. mysqli_close($conn);  
  22. ?>  
Output:
Connected successfully
Table student created successfully