Home  >  Article  >  php教程  >  php 连接数据库并显示所要的数据

php 连接数据库并显示所要的数据

WBOY
WBOYOriginal
2016-05-24 13:25:311277browse

这是一篇php入门教程,讲得就是关于php 连接数据库并显示所要的数据,也就是简单的php+mysql数据库在web网页上的应用实例了,代码如下:

<?php
$Host = "localhost";
$MySQL_UserName = "root";
$MySQL_UserPass = "password";
$MySQL_Database = "db";
$Query = "SELECT * FROM domain";
if (!mysql_connect($Host, $MySQL_UserName, $MySQL_UserPass)) { //开源代码phprm.com
    print "Cannot connect to MySQL: " . mysql_error();
    exit;
}
if (!mysql_select_db($MySQL_Database)) {
    print "Cannot select db<BR>";
    exit;
}
if (!$Result_ID = mysql_query($Query)) {
    print "Query Error: " . mysql_error();
    exit;
}
while ($Result = mysql_fetch_row($Result_ID)) {
    print "------------------<BR>";
    print "$Result[0]<BR>";
    print "$Result[1]<BR>";
    print "$Result[2]<BR>";
    print "$Result[3]<BR>";
    print "-------------------<BR>";
}


本文地址:

转载随意,但请附上文章地址:-)

Statement:
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