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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)