-2

我遇到了这个错误的一些麻烦

警告:mysql_fetch_assoc():提供的参数不是有效的 MySQL 结果资源 事实上,由于没有全局变量,我将所有查询都放在函数中。

我的查询没问题,其他地方的字段名称没有错误。

问题是在本地一切正常,当我把它放到网上时,它不起作用,到处都是我的错误

对于家里我有这个错误:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /web/teamfrancestron/www/lib_php/strongman.php on line 75

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /web/teamfrancestron/www/lib_php/strongman.php on line 90

我的用户在数据库中拥有所有权限,

这是我使用的代码:这是第一个错误

function fetchAccueil() {
    $sql = "SELECT 
                    `content`, `date_maj`, `id_maj`, `titre` 
            FROM `stg_man_home` 
            WHERE 
                    `id` = '1'";
    $result = mysql_query($sql);
    return mysql_fetch_assoc($result);
}

还有其他查询

/** * Fonction qui va chercher l'identité d'une personne. * @param type $id * @return type */

function fetchIdentity($id) {
    $input_id = mysql_real_escape_string($id);
    $query = "SELECT 
                        `nom`, `prenom`
              FROM `stg_man_users`
              WHERE `id` = '{$input_id}'";
    $result = mysql_query($query);
    return mysql_fetch_assoc($result);
}

我真的没有看到名称文件有任何错误,我确信我的查询是有效的资源。(在本地工作,但不在服务器上)。我在 php 5.4

在其他页面上我仍然有同样的错误

任何帮助将不胜感激。

4

3 回答 3

0

检查 的返回值mysql_query。它可以是结果集,也可以只是值false。将您的查询更改为

$result = mysql_query($sql) or die(mysql_error());

你会立即看到问题。

作为旁注:考虑切换到mysqlior PDO,因为mysql_*现在不推荐使用函数。

于 2013-03-17T22:23:33.540 回答
0

你说

WHERE id = '1'

改为执行此操作(删除单引号):

WHERE id = 1

这样您就可以请求与整数而不是字符串匹配。

于 2013-03-17T22:24:50.160 回答
-1

错误消息意味着运行您的查询失败。

测试查询的最简单方法是打开一个 phpmyadmin 或 mysql 控制台(使用相同的用户),并运行这个精确的查询。

于 2013-03-17T22:22:33.623 回答