【网站源码下载】测试MySQL与PHP的连通性的PHP源文件
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>name table</title>
<head>
</head>
<body>
<?php
$link = mysql_connect('MySQL主机IP', 'MySQL账户名', 'MySQL密码');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo "<font size='5' color='red'>PHP Site Connected successfully...</font><br/>";
mysql_select_db("student", $link);
$result = mysql_query("SELECT * FROM name2");
echo "<center>
<div style='width:1000px;'>
<p style='text-align:center '>姓名表</p>
<table width='250' cellspaing='0' cellpadding='0' border='1'>
<tr align='center'>
<th>学号</th>
<th>姓名</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr align='center'>";
echo "<td>" . $row['stuid'] . "</td>";
echo "<td>" . $row['stuname'] . "</td>";
echo "</tr>";
}
echo "</table>
</div>
</center>";
mysql_close($link);
?>
</body>
</html>
MySQL数据库信息:
数据库名:student
数据表名:name2
数据表字段1:stuid
数据表字段2:stuname
本文用于测试http://www.yujianxinliu.com/post-22.html,http://www.yujianxinliu.com/post-543.html的PHP与MySQL的真正连通性。
2019年7月7日补充:
<?php
$link = mysql_connect('127.0.0.1','root','root');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
phpinfo();
?>
如果以上有报错,是因为php版本问题,使用以下代码也可以实现:
<?php
$link = mysqli_connect('127.0.0.1','root','root');
if ($link)
echo "Success...";
else
echo "Failure...";
mysqli_close($link);
phpinfo();
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>name table</title>
<head>
</head>
<body>
<?php
$link = mysqli_connect('127.0.0.1', 'root', 'root');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo "<font size='5' color='red'>PHP Site Connected successfully...</font><br/>";
mysqli_select_db($link, "student");
$result = mysqli_query($link,"SELECT * FROM name2");
echo "<center>
<div style='width:1000px;'>
<p style='text-align:center '>姓名表</p>
<table width='250' cellspaing='0' cellpadding='0' border='1'>
<tr align='center'>
<th>学号</th>
<th>姓名</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr align='center'>";
echo "<td>" . $row['stuid'] . "</td>";
echo "<td>" . $row['stuname'] . "</td>";
echo "</tr>";
}
echo "</table>
</div>
</center>";
mysqli_close($link);
?>
</body>
</html>
您阅读这篇文章共花了:
60电影天堂来访