PHP read MySQL data code _php base

Source: Internet
Author: User
Create a new view.php file with the following contents:
Copy Code code as follows:

<?php
$link =mysql_connect ("localhost", "root", "previous admin password");
if (! $link) echo "No connection succeeded!";
else echo "Connection succeeded!";
?>

In this way, we are connected to the MySQL database, next, is the data read part of the code, according to my MySQL data source table structure of the introduction, we have experimented to read:

Depart varchar (45) Department name
ename varchar (45) Employee name
Pcname varchar (PC) name

These three pieces of data.

In view.php, the preceding code continues to write:

Copy Code code as follows:

<?php
mysql_select_db ("Infosystem", $link); Select Database
$q = "SELECT * from Info"; SQL query Statement
mysql_query ("SET NAMES GB2312");
$rs = mysql_query ($q, $link); Get Data Set
if (! $rs) {die ("Valid result!");}
echo "<table>";
echo "<tr><td> department name </td><td> employee name &LT;/TD&GT;&LT;TD&GT;PC name </td></tr>";
while ($row = Mysql_fetch_row ($rs)) echo "<tr><td> $row [1]</td><td> $row [2]</td><td   > $row [3]</td></tr> "; Display data
echo "</table>";
Mysql_free_result ($RS); Closing datasets
?>
where "Infosystem" is the database name and "Info" is the name of the table. We can revise them according to their own circumstances as appropriate.

Then, run it ~ how ~ the data is not successfully read it?

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.