PHP read MySQL data code_PHP tutorial

WBOY
Release: 2016-07-21 15:52:16
Original
830 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 "The connection was not successful!";
else echo "The connection was successful!";
?>

In this way, we are connected to the MySQL database. Next, is the code for the data reading part. According to the introduction of my MySQL data source table structure, we experimentally To read:

department varchar(45) department name
ename varchar(45) employee name
pcname varchar(45) PC name

.

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"; NAMES GB2312");                                                                                 ";
echo "< /tr>";
while($row = mysql_fetch_row($rs)) echo ""; //Display data
echo "
Department nameEmployee namePC name
$row[1]$row[2]< /td>$row[3]
";
mysql_free_result($rs); /Close the data set
?>

Among them, "infosystem" is the database name and "info" is the table name. You can modify it as appropriate according to your own situation.

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




http://www.bkjia.com/PHPjc/318952.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/318952.htmlTechArticleCreate a new view.php file with the following content: Copy the code as follows: ?php $link=mysql_connect("localhost ","root","Previous administrator password"); if(!$link)echo"The connection was not successful!"; elsee...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!