I am having issues trying to create a new MySQL database in php,
my code is:
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = ‘somepassword’;
$conn = new mysqli($dbhost, $dbuser, $dbpass);
if(!$conn->connect_error )
{
die('Could not connect: %s' . $conn->connect_error);
}
echo "Connected successfully
";
$sql = "CREATE DATABASE TUTORIALS2";
if($conn->query($sql)===TRUE){
echo "Created the database
";
}
else {
echo "Failed to create the database".$conn->error;
}
//Close the database
$conn->close();
?>
MySQL connects fine but it won't allow me to create a new database. Not a clue what I'm doing wrong here. Any pointers would be greatly appreciated!
Second Edit: I somehow missed this, apologies.
You have a mistake here:
if(!$conn->connect_error )
should be
if($conn->connect_error )
see here http://php.net/manual/en/mysqli.connect-error.php
Edit:
run this query SHOW GRANTS FOR 'root'@'localhost';
either from php or from PhpMyAdmin or similar and see if the user root has the privilege to create databases.
More here http://dev.mysql.com/doc/refman/5.0/en/show-grants.html
First of all you need to enable error_reporting and second you have some bad quotes on this line $dbpass = ‘somepassword’;
replace like this
$dbpass = 'somepassword';