CREATE DATABASE mydbpdo
SQLSTATE[HY000]: General error: 1007 Can't create database 'mydbpdo'; database exists
<?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection try { $conn = new PDO("mysql:host=$servername", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Create database $sql = "CREATE DATABASE myDBPDO"; // use exec() because no results are returned $conn->exec($sql); echo "Database created successfully<br>"; } catch(PDOException $e) { echo "" . $sql . "<br>" . $e->getMessage() . ""; } $conn = null; ?>