下面是一个php连接数据库操作的测试代码,你可以参考:
$id = mysql_connect("localhost", "root", "123456") or die(mysql_error());
$ok = mysql_select_db("zf2", $id) or die(mysql_error());
if ($ok) {
echo "ok";
} else {
echo "no";
}
$rs = mysql_query("select * from album order by artist asc");
if ($rs) {
echo "sdfasf";
} else {
echo "fail";
}
if (mysql_num_rows($rs) != 0) {
while($row = mysql_fetch_array($rs)) {
print_r($row['id'] . "
");
}
}
unset($row);
mysql_free_result($rs);
mysql_close($id);