Home > Backend Development > PHP Tutorial > merry lonely christmas PHP read MySQL data code

merry lonely christmas PHP read MySQL data code

WBOY
Release: 2016-07-29 08:38:06
Original
832 people have browsed it

Create a new view.php file with the following content:

Copy the code 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 are connected to the MySQL database. Next, is the data reading part Code, according to the introduction of my MySQL data source table structure, we experimentally read:
Department varchar(45) Department name
ename varchar(45) Employee name
pcname varchar(45) PC name
These three paragraphs data.
Continue writing the previous code in view.php:

Copy the code The code is as follows:


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 the data set
if(!$rs){die ("Valid result!");}
echo "

";
echo "";
while($row = mysql_fetch_row($rs)) echo ""; //Display data
echo "
Department NameEmployee Name
$row[1]$row[3]
";
mysql_free_result($ rs);                                                                                                                                                                                                                      //Close the data set
?> You can modify it as appropriate according to your own situation.
Next, run it~how~is the data read successfully?


The above introduces the merry lonely christmas PHP code for reading MySQL data, including the content of merry lonely christmas. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template