PHP to read MySQL data code _ PHP Tutorial

Source: Internet
Author: User
PHP reads MySQL data code. Create a view. php file with the following code :? Php $ linkmysql_connect (localhost, root, previous administrator password); if (! $ Link) echo no connection successful !; Elsee creates a view. php file with the following content:

The code is as follows:


$ Link = mysql_connect ("localhost", "root", "previous administrator password ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
?>


In this way, we connect to the MySQL database. Next, we will read some of the code for reading data. based on the introduction of the MySQL data source table structure, we will try to read:

Depart varchar (45) department name
Ename varchar (45) employee name
Pcname varchar (45) PC name

The three data segments.

In view. php, write the code next to the front:

The code is as follows:


Mysql_select_db ("infosystem", $ link); // select a database
$ Q = "SELECT * FROM info"; // SQL query statement
Mysql_query ("set names GB2312 ");
$ Rs = mysql_query ($ q, $ link); // Obtain a dataset
If (! $ Rs) {die ("Valid result! ");}
Echo"




";Echo" ";While ($ row = mysql_fetch_row ($ rs) echo" "; // Display DataEcho"
Department name Employee Name PC name
$ Row [1] $ Row [2] $ Row [3]
";
Mysql_free_result ($ rs); // Close the dataset
?>

"Infosystem" indicates the database name and "info" indicates the table name. You can modify the settings as needed.

Next, run it ~ How about ~ Is the data successfully read?

The pipeline code is as follows :? Php $ link = mysql_connect ("localhost", "root", "previous administrator password"); if (! $ Link) echo "no connection successful! "; Elsee...

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.