<?php
/*
* Created on Dec 20, 2010
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
//phpinfo();
$user = 'root';
$password = '';
$conn = mysql_connect('localhost', $user, $password) or die('Could not con' . mysql_errno());
echo '<br><b>第一步成功连接</b><br>';
$db = 'test';
mysql_select_db($db) or die('Could not select database (' . $db . ' ) because of ' . mysql_error());
echo '<b>第二步: </b>成功连接到(' . $db . ')';
$query = 'SELECT * FROM `haha` WHERE 1 LIMIT 0, 30 ';
$result = mysql_query($query) or die('Query failed' . mysql_error());
echo '<br><br><b>正在获取数据...</b><br>';
echo '<table border = "1" width = "500">\n';
$count = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { //数据转换成array位置索引成对的出现。
echo '\t<tr>\n';
foreach ($line as $key => $value) {
echo '\t\t<td>' .$value.'</td>\n';
}
echo '\t</tr>\n';
$count++;
}
echo "</table>\n";
if ($count < 1) {
echo '<br><br>数据库暂时没有数据<br><br>';
} else {
echo '<br><br>表格中有' . $count . '记录<br><br>';
}
mysql_free_result($result);
mysql_close($conn); //php引擎会帮你做可以不写。
?>