php怎么链接mysql5.6并创建数据库

如题所述

下面是一个php连接数据库操作的测试代码,你可以参考:
<?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'] . "<br>");
}
}
unset($row);
mysql_free_result($rs);
mysql_close($id);
温馨提示:答案为网友推荐,仅供参考
相似回答