mysql_fetch_assoc()期望参数1是资源,对象给出[重复]
问题描述:
This question already has an answer here:
Im trying to store the results from my query into a variable but get this error
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given
$result = mysqli_query($con,"Select objectID from objects where objectName = '$_POST[relations]'");
if($result === FALSE) {
die(mysqli_error()); // TODO: better error handling
}
$result = mysql_fetch_assoc($result);
echo $result;
Any other way of storing this variable?
</div>
此问题已经存在 这里有一个答案: p>
-
mysql_fetch_array()/ mysql_fetch_assoc()/ mysql_fetch_row()/ mysql_num_rows etc ...期望参数1为资源或结果
32 answers
span>
li>
ul>
div>
我试图将查询结果存储到变量中但得到此错误 p>
警告:mysql_fetch_assoc()期望参数1为资源,给定对象 p>
$ result = mysqli_query($ con,“从objectName ='$ _POST [relations]''的对象中选择objectID); nif($ result = == FALSE){ die(mysqli_error()); // TODO:更好的错误处理 } $ result = mysql_fetch_assoc($ result); echo $ result; code> pre>
任何其他存储方式 这个变量? p> div>
答
You start with mysqli_*
, but continue with mysql_*
.
Change mysql_fetch_assoc
to mysqli_fetch_assoc
.
Documentation
You can view the documentation on mysqli_fetch_assoc here.