douningle7944 2013-03-17 22:18
浏览 52
已采纳

警告:mysql_fetch_assoc():提供的参数不是有效的MySQL [重复]

I met some trouble with that error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in In fact for not having global variables I put all my query in functions.

My queries are ok, no mistakes in the fields name of where ever else.

The trouble is that on local all is fine working, when I put it online, it does not workd, and everywhere it return me some mistakes

for the home I have this mistakes:

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

My user have all privilege in the database,

here is the code I use : here is for the first mistake

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);
}

And there for the other query

/** * 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);
}

I realy do not see any mistakes on names fileds, I'm sure that my queries are valid ressources. (works on local but not on the server). Im on php 5.4

On other pages I have still the same mistakes

Anykind of help will be much appreciated.

</div>
  • 写回答

3条回答 默认 最新

  • dtslobe4694 2013-03-17 22:23
    关注

    Check the return value of mysql_query. It can be a result set, but also just the value false. Change your query to

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

    and you will see the problem at once.

    As a sidenote: consider switching to mysqli or PDO, because mysql_* functions are deprecated by now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line