Page 346 - Computer Software Application TP - Volume 1
P. 346
COMPUTER SOFTWARE APPLICATION - CITS
<html >
<head>
<title> create a table </title>
</head>
<body>
<?php
// Database connection parameters
$servername = “localhost”; // Change this if MySQL server is on a different host
$username = “your_username”; // Change this to your MySQL username
$password = “your_password”; // Change this to your MySQL password
$database = “example_db”; // Change this to your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: “ . $conn->connect_error);
}
// sql to create table
$sql = “create table persons(
id int, first_name varchar(30), last_name varchar(30) , email varchar(70))”;
if ($conn->query($sql) === TRUE) {
echo “Table created successfully”;
} else {
echo “Error creating table: “ . $conn->error;
}
$conn->close();
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
331
CITS : IT & ITES - Computer Software Application - Exercise 61