home *** CD-ROM | disk | FTP | other *** search
- <?php
- // ╟ß╟╩╒╟ß π┌ π╧φ╤ ▐µ╟┌╧ ╟ß╚φ╟Σ╟╩
- $servername = "localhost";
- $username = "root";
- $password = "";
-
- try {
- $conn = new PDO("mysql:host=$servername", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "CREATE DATABASE t001";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "Database created successfully<br>";
- } catch(PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
-
- // ┼Σ╘╟┴ ╠╧µß
- $dbname = 't001';
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-
- // sql to create table
- $sql = "CREATE TABLE `table1` (
- `id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
- `col1` VARCHAR( 124 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,
- `col2` TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
- ) ENGINE = MYISAM ;";
-
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "Table table1 created successfully<br>";
- } catch(PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
-
- // ╟╧╬╟ß ╙╪╤φΣ πΣ ╟ß╚φ╟Σ╟╩
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "INSERT INTO `table1` (`id`, `col1`, `col2`) VALUES
- (NULL, 'Ahmed', 'He is a teacher.'),
- (NULL, 'Ali', 'He is a doctor.');";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "New 2 records created successfully<br>";
- } catch(PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
-
- // ╟▌╤╟█ ╠╧µß
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "TRUNCATE TABLE `table1`;";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "TRUNCATE table successfully<br>";
- } catch(PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
-
- // ═╨▌ ╠╧µß
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "DROP TABLE `table1`;";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "DROP TABLE successfully<br>";
- } catch(PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
-
- // ═╨▌ ▐╟┌╧╔ ╚φ╟Σ╟╩
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "DROP DATABASE `t001`;";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "DROP DATABASE successfully<br>";
- } catch(PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
-
- $conn = null;
- ?>
-
-