【发布时间】:2015-12-18 11:06:29
【问题描述】:
我开始将使用 Mysql 的网站转换为使用 Mysqli,但遇到了一些问题。 有人可以帮助我如何使用 Mysqli 正确连接和查询 Mysql。
1) 以下是我网站上的 .Error 警告消息:
a) 警告:mysql_query():第 3556 行 /myside/xxxx/xxxxx/functions.php 中用户“localhost”的访问被拒绝(使用密码:否)
b) 警告:mysql_query():无法在第 3556 行的 /myside/xxxx/xxxxx/functions.php 中建立到服务器的链接
c) 警告:mysql_results() 期望参数 1 是资源,布尔值在 /myside/xxxx/xxxxx/functions.php 第 3558 行给出
2) MYSQL Query 函数代码,我用于从第 3544 行到第 3558 行:
// Get Custom Post Type post count
function get_stats($uid,$type,$sub_type = "all") {
if ($type == "reviews") {
$result = mysql_query("SELECT COUNT(*) FROM wp_comments WHERE user_id = $uid AND comment_approved = 1");
} elseif ($type == "listings") {
if ($sub_type == "all") {
$post_types = get_post_types_custom(unserialize(EXCLUDED_CUSTOM_POST_TYPES));
} else {
$post_types = "'".$sub_type."'";
}
$result = mysql_query("SELECT COUNT(*) FROM wp_posts WHERE post_author = $uid AND post_type IN($post_types) AND post_status = 'publish'");
} else {
$result = mysql_query("SELECT COUNT(*) FROM wp_posts WHERE post_author = $uid AND post_type = '$type' AND post_status = 'publish'");
}
return mysql_result($result,0);
非常感谢!
【问题讨论】:
-
我没有看到任何错误信息?!警告与错误不同...另外,我在您提供的代码中看不到任何 mysqli ..
-
不要混合
mysql_*和mysqli_*`