Merry Lonely Christmas php read MySQL data code

Source: Internet
Author: User
Create a new view.php file with the following contents:

Copy the Code code as follows:


$link =mysql_connect ("localhost", "root", "previous Administrator password");
if (! $link) echo "Not connected successfully!";
else echo "connected successfully!";
?>


In this way, we connected to the MySQL database, and then the data read part of the code, according to my MySQL data source table structure of the introduction, we are experimental to read:
Depart varchar (45) Department name
ename varchar (45) Employee name
Pcname varchar PC Name
These three pieces of data.
In the view.php, immediately preceding code continues to write:

Copy the Code code as follows:


mysql_select_db ("Infosystem", $link); Select Database
$q = "SELECT * from Info"; SQL query Statements
mysql_query ("SET NAMES GB2312");
$rs = mysql_query ($q, $link); Get Data Set
if (! $rs) {die ("Valid result!");}
echo "




"; echo " "; while ($row = Mysql_fetch_row ($rs)) echo " "; Show Data echo "
Department Name Employee Name PC Name
$row [1] $row [2] $row [3]
";
Mysql_free_result ($RS); To close a data set
?>

where "Infosystem" is the database name, "Info" is the name of the table. You can modify it according to your own circumstances as appropriate.
Next, run it ~ how ~ is the data being read smoothly?

The above describes the merry lonely Christmas php read the MySQL data code, including Merry Lonely Christmas content, I hope the PHP tutorial interested in a friend helpful.

  • 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.