A question about executing mysql statements in php is about to blow up the header.

Source: Internet
Author: User
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 ."'";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.