Reputation: 95
I've been playing around with creating a new user and I keep getting this error:
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 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `testingUser' at line 3
and my query is:
mysql_query("
GRANT USAGE ON *.* TO '$user'@'localhost' IDENTIFIED BY '$pass';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `$user\_database`.* TO '$user'@'localhost';
GRANT SELECT (Table_priv, Column_priv, Table_name, Db, User, Host) ON `mysql`.`tables_priv` TO '$user'@'localhost';
GRANT SELECT ON `mysql`.`host` TO '$user'@'localhost';
GRANT SELECT (Host, Create_priv, Shutdown_priv, Delete_priv, User, Process_priv, Reload_priv, Alter_priv, Super_priv, Grant_priv, Create_tmp_table_priv, Execute_priv, Repl_client_priv, Insert_priv, Repl_slave_priv, Lock_tables_priv, References_priv, Index_priv, File_priv, Drop_priv, Show_db_priv, Select_priv, Update_priv) ON `mysql`.`user` TO '$user'@'localhost';
GRANT SELECT ON `mysql`.`db` TO '$user'@'localhost';");
Upvotes: 1
Views: 2872
Reputation: 360632
You cannot issue multiple queries in a single mysql_query()
call. It's a security restriction to prevent some forms of SQL injection. You'll have to issue each grant query in a separate mysql_query()
call.
mysql_query("GRANT ...");
mysql_query("GRANT ...");
etc...
Upvotes: 3