theaussie
asked on
PHP - MySQL Grant
I have problems with using 'GRANT'. My aim is to create a database, then assign permissions for the new user:
<?php
// set your infomation.
$dbhost='localhost';
$dbusername='root';
$dbuserpass='rootabc';
$dbname='testbase';
$newuser='abc';
$newuserpasswd='abc123';
// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";
// create the database.
$dbname=$newuser."_".$dbna me;
if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error());
echo "success in database creation.";
//grant user rights.
if (!mysql_query("grant all on $dbname.* to $newuser identified by $newuserpasswd")) die(mysql_error());
echo "success in grant creation.";
?>
The database is created Ok, but fails on the 'Grant' sections. The error message reads:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'abc123' at line 1
Any help appreciated.
<?php
// set your infomation.
$dbhost='localhost';
$dbusername='root';
$dbuserpass='rootabc';
$dbname='testbase';
$newuser='abc';
$newuserpasswd='abc123';
// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";
// create the database.
$dbname=$newuser."_".$dbna
if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error());
echo "success in database creation.";
//grant user rights.
if (!mysql_query("grant all on $dbname.* to $newuser identified by $newuserpasswd")) die(mysql_error());
echo "success in grant creation.";
?>
The database is created Ok, but fails on the 'Grant' sections. The error message reads:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'abc123' at line 1
Any help appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.