webdev.ramyash@gmail.com

Web Development: Create a Table using PHP and MySQL.


Unlock the World of Web & Tech – Learn, Innovate, and Excel!

Create a Table using PHP and MySQL.

<?php


$con=mysqli_connect("localhost","user","password","test_db");


// Check connection


if (mysqli_connect_errno())


{


echo "Failed to connect to MySQL: " . mysqli_connect_error();

}


// Create table

$sql="CREATE TABLE Persons(FirstName CHAR(30),LastName CHAR(30),Age INT)";


// Execute query

if (mysqli_query($con,$sql))

{

echo "Table persons created successfully";

}

else

{

echo "Error creating table: " . mysqli_error($con);

}

?>

No comments:

Post a Comment