你能算出我的密码吗?所有的代码都是:,No数据库,选择了,它不会从数据库中获取数据。服务器os是Ubuntu或OS。我拔头发已经好几个小时了。
<?php
mysqli_connect("localhost", "root", "");
mysql_select_db("hit-counter");
$sql_get_count = mysql_query("SELECT id FROM hit_info ORDER BY id DESC LIMIT 1");
if($sql_get_count === FALSE) {
die(mysql_error());
}
while($row = mysql_fetch_assoc($sql_get_count)) {
print_r($row);
}
?>我试过这个,也是一样的
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("hit-counter");
$sql_get_count = mysql_query("SELECT id FROM hit_info ORDER BY id DESC LIMIT 1");
if($sql_get_count === FALSE) {
die(mysql_error());
}
while($row = mysql_fetch_assoc($sql_get_count)) {
print_r($row);
}
?>发布于 2016-03-11 07:41:44
代码中有错误。使用mysqli_函数连接服务器,但使用不推荐的函数mysql_来选择数据库。
试试下面的代码:
mysqli_connect("localhost", "root", "");
mysqli_select_db("hit-counter");使用mysqli_时的另一个选项是在连接到服务器期间选择所需的数据库:
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");发布于 2016-03-11 07:40:21
您没有提到数据库名:试试这个
<?php
$con = mysqli_connect("127.0.0.1","root","654321","testV2") or die("Some error occurred during connection " . mysqli_error($con));
// Write query
$strSQL = "SELECT id FROM did ORDER BY id DESC LIMIT 1";
// Execute the query.
$query = mysqli_query($con, $strSQL);
while($result = mysqli_fetch_array($query))
{
echo $result["id"]."
";
}
// Close the connection
mysqli_close($con);
?>发布于 2016-03-11 07:41:14
您不能交换mysql和mysqli函数,请将mysql_select_db修改为mysqli_select_db。
https://stackoverflow.com/questions/35934644
复制相似问题