当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Catchable fatal error: Object of class mysqli_result could not be converted to string i cant find it

问题描述:

Why wont this work?

function user_data($user_id) {

global $con;

$user_id = $_SESSION['user_id'];

$func_num_args = func_num_args();

$func_get_args = func_get_args();

if ($func_num_args > 1) {

unset($func_get_args[0]);

$fields = '`' . implode('`, `', $func_get_args) . '`';

$res = mysqli_query($con, "SELECT $fields as velden FROM `users` WHERE `user_id` = '$user_id'");

$row = mysqli_fetch_array($res);

}

}

I searched a lot but cannot find the fix.

网友答案:

This error almost always means that the query has failed so examine the query.

Try this :

$fields = '`' . implode('`, `', $func_get_args) . '`';
$sql = "SELECT $fields as velden FROM `users` WHERE `user_id` = '$user_id'";
echo $sql;

Now if the error is not obvious to the eye, copy the query and run it in phpmyadmin or whatever tool you use to manage your Databases.

Almost definitely this part of the query is going to cause an error if there is more than one field in your $fields array. SELECT $fields as velden so try removing the as velden.

分享给朋友:
您可能感兴趣的文章:
随机阅读: