Hey there.
I am new to PHP, and I thought it was time I started learning it. I’m good with HTML / CSS etc, but I need to learn PHP for Wordpress and creating plugins etc. I’ve got the basics alright, which most of the time I can BS my way out of it; although I’m planning to be learning it in depth this summer holidays. I’ve been messing around with MySQL and PHP lately and I’ve come across an error.
I’ve set up the database connection to make sure it gives me a Success or Failure error whenever it creates / doesn’t create the database. At the moment, it only shows the failure with the “The database (database name) wasn’t created; it already exists.”, although when I look in PHPMyAdmin the database was created successfully?
Here is my code:
<?php
// Enter your MySQL Server Details and Creation Details here.
$host = "localhost";
$username = "root";
$pass = "";
$db = "localhost";
// This connects to the Server, with a kill message.
$connect = mysql_connect($host, $username, $pass);
if (!$connect)
{
die("Could not connect to the server. ") . mysql_error() . (".") ;
}
// Create the Database with the details.
mysql_query("CREATE DATABASE $db");
// Messages for creation or failure.
if (mysql_query("CREATE DATABASE $db", $connect))
{
echo("Success!");
}
else
{
echo("There was a problem creating the database. ") . mysql_error() . (".");
}
mysql_close($connect);
?>
Thanks to all in advance for the help.