A question about executing mysql statements in php is about to blow up the header! Php executes the mysql statement for adding a user, asking for advice from the predecessors. I did not do a good job for one night. The following [POST obtained] adds a $ user to localhost, and the password is $ pass, create a database named $ user and grant the read/write permission to the database. If no variable is added, I will handle it. when I add a database, I feel dizzy. the old one is about executing mysql statements in php, I want to blow up my head. please be a senior!
Php executes the mysql statement for adding a user, asking for advice from the predecessors. I did not do a good job this evening, as shown in the following [obtained by POST]
Add $ user to localhost with the password $ pass, create a database named $ user, and grant the read/write and delete permissions,
I will do it without adding variables, and I will feel dizzy when I add them, and I will always prompt a syntax error.
Please do not pass your teeth. you are my hope!
------ Solution --------------------
$ User = 'user ';
$ Pass = 'password ';
$ SQL = "crearte databuse $ user ";
$ SQL = <SQL
Grant select, insert, delete
On $ user
To $ user @ localhost identifed by '$ pass'
SQL;
Connect to the database as root and execute two $ SQL statements in sequence.
If you have any syntax errors, please modify them by yourself.
------ Solution --------------------
First
You are not here
$ User = 'user ';
$ Pass = 'password ';
$ SQL = "crearte databuse $ user ";
$ SQL = "create database'" + $ user + "'";
Because you sent it to the mysql client, it cannot identify the parsing $ user
------ Solution --------------------
What about the landlord's code?
PHP code
$ User = 'user'; $ pass = 'password'; $ SQL = "crearte databuse $ user"; $ SQL = "create database'". $ user ."'";