MySQLi 的数据库使用(不建议)

MySQL 飞快学 373浏览

原生 MySQL API:http://php.net/manual/en/book.mysql.php

迭代读取数据

示例:http://example.phpsoeasy.com/sakila/film-mysql.php

<?php
require_once 'db_config.php';

$conn = mysql_connect($host, $user, $pass, $db);
if (!$conn) die("Connection failed: " . mysql_connect_error());
mysql_select_db($db, $conn);
mysql_query("set names 'utf8'");  // gbk
$sql = "select * from film LIMIT 0 , 10";
$result= mysql_query($sql, $conn);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>Sakila 影片</title>
</head>
<body>
<table>
  <tr>
    <td>名称</td>
    <td>发布时间</td>
  </tr>
<?php while($row = mysql_fetch_array($result)) : ?> 
  <tr>
    <td><?php echo $row["title"];?></td>
    <td><?php echo $row["release_year"];?></td>
  </tr> 
<?php endwhile; ?>  
</table>
</body>
</html>