Heim  >  Artikel  >  php教程  >  php 连接数据库并显示所要的数据

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

WBOY
WBOYOriginal
2016-05-24 13:25:311273Durchsuche

这是一篇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>";
}


本文地址:

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn