Tags:
create a database in php, php tutorial, how to create database in php, use PDO create database in php,php with mysql, create datbase example in php, code create database in php, php example, code php example,how to code php example, php create database example.
Introduce create database in php
To create and delete a database you should have admin privilege. Its very easy to create a new MySQL database. PHP uses mysql_query function to create a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
Performed create database in php
Step 1. Connect php to mysql use pdo
$server = "mysql:host=localhost";Step 2. Create database in php use pdo
$username ="root";
$password="";
$conn = new PDO($server,$username,$password);
if(!$conn){
echo "Don't connect ";
}
$SQL ="Create database tes_db_pdo";
$conn ->exec($SQL) or die(print_r($conn ->errorInfo()))
All code below:
<html>
<head>
<title>How to Create database in php using PDO</title>
</head>
<body>
<?php
$server = "mysql:host=localhost";
$username ="root";
$password="";
$conn = new PDO($server,$username,$password);
if(!$conn){
echo "Don't connect ";
}
$SQL ="Create database tes_db_pdo";
$conn ->exec($SQL) or die(print_r($conn ->errorInfo()))
?>
</body>
</html>
No comments:
Post a Comment