Jump to: navigation, search

PHP MySQL PDO Create Table

From w3cyberlearnings

Contents

PHP PDO Create Table

Create A table uses $db->query($table).

Syntax PDO Create Table


$sql = "CREATE TABLE IF NOT EXISTS user_infor (
   id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	first_name VARCHAR(200) NOT NULL,
	last_name VARCHAR(200) NOT NULL,
	email VARCHAR(200) NOT NULL	
)";

$sq = $db->query($sql);

Example 1

<?php

$dns = 'mysql:host=localhost;dbname=w3cyberlearning';
$user = 'user2000';
$pass = 'password2000';

$db = new PDO($dns, $user, $pass);


$sql = "CREATE TABLE IF NOT EXISTS user_infor (
   id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	first_name VARCHAR(200) NOT NULL,
	last_name VARCHAR(200) NOT NULL,
	email VARCHAR(200) NOT NULL	
)";

$sq = $db->query($sql);

if ($sq) {
	echo 'created';
}
?>

Output

created


Related Links


Navigation
Web
SQL
MISC
References