使用php连接mysql

 

<?php

$mysql_server_name='127.0.0.1';
$mysql_username='root';
$mysql_password='';
$mysql_database='test';

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password)or die("error!can not link mysql!");
mysql_query("SET NAMES utf8");
mysql_select_db($mysql_database);

$result1 = mysql_query("select * from city where id <15");


echo "<table border ='1'>
<tr>
<th>ID</th>
<th>NAME</th>
<th>CODE</th>
</tr>";

while($row = mysql_fetch_array($result1))
{
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['code']."</td>";
echo "</tr>";
}
echo "</table>";

echo "<hr>";

?>

效果:

QQ20160718135851

此条目发表在MySql分类目录,贴了, 标签。将固定链接加入收藏夹。