mysql query result in php variable

前端 未结 5 1076
误落风尘
误落风尘 2020-11-30 07:56

Is there any way to store mysql result in php variable? thanks

$query = \"SELECT username,userid FROM user WHERE username = \'admin\' \";
$result=$conn->q         


        
5条回答
  •  萌比男神i
    2020-11-30 08:51

    $query    =    "SELECT username, userid FROM user WHERE username = 'admin' ";
    $result    =    $conn->query($query);
    
    if (!$result) {
      echo 'Could not run query: ' . mysql_error();
      exit;
    }
    
    $arrayResult    =    mysql_fetch_array($result);
    
    //Now you can access $arrayResult like this
    
    $arrayResult['userid'];    // output will be userid which will be in database
    $arrayResult['username'];  // output will be admin
    
    //Note- userid and username will be column name of user table.
    

提交回复
热议问题