How to create table in mysql php example
In this example we have created table in MySQL PHP. We have created table UserInformation "FirstName", "LastName" ,"Address" ,"Age"). We have added the CREATE TABLE statement to the mysqli_query() function to execute the command.
MySQL Syntax:-
$sql="CREATE TABLE UserInformation(FirstName CHAR(30),LastName CHAR(30),Address CHAR(50),Age INT)";
Example:
<html"> <head> <title>Create Table</title> </head> <body> <?php $connection=mysqli_connect('localhost','root','','naulej'); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Create table $sql="CREATE TABLE UserInformation(FirstName CHAR(30),LastName CHAR(30),Address CHAR(50),Age INT)"; // Execute query if (mysqli_query($connection,$sql)) { echo "Table UserInformation created successfully"; } else { echo "Error creating table: " . mysqli_error($connection); } ?> </body> </html> |
Output:-
Error creating table
No comments:
Post a Comment