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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?