dregduc63699 2018-05-26 05:30
浏览 116
已采纳

错误:PHP中的数组到字符串转换

I'm getting this error while trying to execute my function.

The columns of my database are 100% correct and i tested every request and it worked!

Error :

[26-May-2018 05:21:49 UTC] PHP Notice:  Array to string conversion in C:\wamp64\www\gcm\database.php on line 82

[26-May-2018 05:21:49 UTC] PHP Warning:  mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\gcm\database.php on line 88

My function:

function getHistoriqueNotification($user,$mdp){
$com = new DbConnect();
$message=array();
$sql="select UTLR_UID from adm_utilisateurs where UTLR_LOGIN='$user' and UTLR_MDP='$mdp'";
$result=mysqli_query($com->getDb(),$sql);
$getID = mysqli_fetch_assoc($result);
$userID = $getID['UTLR_UID'];
$sqli = "SELECT alr_alertes.ALRT_DES_LN1,alr_alertes.ALRT_PHOTO,alr_historiques.AHIS_DES_LN1,alr_historiques.AHIS_DATEHEURE from alr_alertes,alr_historiques WHERE alr_alertes.ALRT_UID=alr_historiques.ALRT_UID AND alr_historiques.UTLR_UID=$userID";
$resulti = mysqli_query($com->getDb(),$sqli);
while($row=mysqli_fetch_assoc($resulti)){
$message = array('photo' =>$row['ALRT_PHOTO'] , 'titre' => $row['ALRT_DES_LN1'] , 'dateHeure' =>$row['AHIS_DATEHEURE'] , 'detail' => $row['AHIS_DES_LN1']);
}

return $message;
}
  • 写回答

1条回答 默认 最新

  • douruye5092 2018-05-26 06:02
    关注

    When using mysqli you need to free up the results per each query. Since you made a query with the $sql and then a second query using the $sqli without freeing up the results in between the two queries it caused you the problem.

    Please read on these mysqli functions: http://php.net/manual/en/mysqli-result.free.php

    Notice I closed your first connection and then made a second one. I think you can do this by keeping the same connection but calling mysqli_free_result() prior to your next query. I am not all that familiar with mysqli but I think that's right.

    function getHistoriqueNotification($user, $mdp){
    
    $com = new DbConnect();
    $message=array();
    $sql = "select UTLR_UID from adm_utilisateurs where UTLR_LOGIN='$user' and UTLR_MDP='$mdp'";
    $result = mysqli_query($com->getDb(),$sql);
    $getID = mysqli_fetch_assoc($result);
    $userID = $getID['UTLR_UID'];
    
    mysqli_close($com);
    unset($com);
    
    $com1 = new DbConnect(); //This is really just a test.
    
    $sqli = "SELECT alr_alertes.ALRT_DES_LN1,alr_alertes.ALRT_PHOTO,alr_historiques.AHIS_DES_LN1,alr_historiques.AHIS_DATEHEURE from alr_alertes,alr_historiques WHERE alr_alertes.ALRT_UID=alr_historiques.ALRT_UID AND alr_historiques.UTLR_UID=$userID";
    
    if ($resulti = mysqli_query($com1->getDb(), $sqli)){
    
        while($row = mysqli_fetch_assoc($resulti)){
    
        //Added the [] after message.
        $message[] = array(
          'photo'     =>$row['ALRT_PHOTO'], 
          'titre'     =>$row['ALRT_DES_LN1'], 
          'dateHeure' =>$row['AHIS_DATEHEURE'],
          'detail'    =>$row['AHIS_DES_LN1']
        );
    
      }
    
    }else{
    
      echo("Error description: " . mysqli_error($com1->getDb()));
    
      }
    
    print_r($message); //<---This will show you if you have a result.
    return $message;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛