How to attach a database in PHP F

Source: Internet
Author: User
Tags mysql in

The first step is to create a connection

$a = mysql_connect ("localhost", "root", "");

The meaning of the parameters inside the parentheses:

1.localhost--ip address, localhost is the meaning of the machine, if you need to connect to other servers, then you need to enter the IP address of the server to connect

2.root--user name, the user name of the server to connect to, and the user name to save when creating the server what to write

3. ""--server password, the password to connect to the server, no password, in double quotation marks do not write anything, but can not omit double quotation marks

4. $a-If the connection is successful, a MySQL connection ID will be returned or the connection fails to return a false, since there is a return value, we need to create a variable to receive it

Report:

How to quickly modify the server password:

1. In the Server menu bar, select MySQL (mysql console)

Click to enter the C # interface:

Here enter the password means please enter the password, please enter the server password, if not directly click the ENTER key

Then enter a sentence behind mysql>

Mysql>use mysql;--This sentence means to choose which database

Enter run

Next you need to write a modified statement:

Update mysql.user Set password = password (123) where user = ' root ';

Modify this Mysql.user table, and then set the password to 123, where the equal sign to the right of the password must be uppercase, otherwise it will be an error.

The password is then modified to complete.

Second Select the database to manipulate

mysql_select_db ("MyDB", $a);

Name of the mydb--database

$a--What to use to connect to the database

The third step is to write the SQL statement

$q = "SELECT * from Nation";--query all data in the Nation table

Fourth step Execute SQL statement

$w =mysql_query ($q);--Call mysql_query () This method to execute the SQL statement, and when it is done, it returns a result set, and we need to create another variable to receive it.

$Q--variables that represent SQL statements

$W--variables that accept the result set

Fifth step reading data from the result set

The returned result set can be read using the Mysql_fetch_xxx method.

while ($e = Mysql_fetch_row ($w))

{

Var_dump ($e);

}

Example: mysql_fetch_row--reading data from a result set

Report:

Because the encoding format is inconsistent, it will appear in Chinese garbled, Chinese garbled solution:

1. Character set selection Utf-8 when creating a database

2. Find the My.ini configuration file in MySQL in the database

Double-click to open, in the last [mysqld] inside add a sentence: Character_set_server=utf8 completed save exit

3. The encoding format of the modified page is Utf-8

2016.6.5 Lonely Nightingale

How to attach a database in PHP F

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.