php 警告:mysql_query() 期望参数 1 是字符串,
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5814401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mysql_query() expects parameter 1 to be string,
提问by Henkka
I get this*Warning: mysql_query() expects parameter 1 to be string*
when I am trying to run this query in my PHP-code and I don't understand why.
*Warning: mysql_query() expects parameter 1 to be string*
当我试图在我的 PHP 代码中运行这个查询时,我得到了这个,但我不明白为什么。
The query runs when entered from the commandline, but I cant get it to run in PHP. Could someone please help me with this?
从命令行输入时会运行查询,但我无法让它在 PHP 中运行。有人可以帮我解决这个问题吗?
$pickass = mysql_query("SELECT MAX(aid) FROM asset");
$pickassssult = mysql_query($pickass);
Thanks.
谢谢。
回答by ebrandell
Why exactly are you running two mysql_query() statements on one another?
为什么要在彼此上运行两个 mysql_query() 语句?
You should simply need to do something like this:
你应该只需要做这样的事情:
<?php
// Set up connection parameters (mysql_connect() for example)
$query = "SELECT MAX(aid) FROM asset";
$result = mysql_query($query);
// mysql_fetch_array() etc etc...
?>
Hope that helps.
希望有帮助。
回答by ypercube??
$pickass = "SELECT MAX(aid) FROM asset" ;
$pickassssult = mysql_query($pickass) ;
回答by Nanne
Well you're running "mysql_query", putting the result in $pickass
, and then run mysql_query
again on the resultset. Mysql_query
(in the second line) wants a string, not a resultset. Don't you mean to do a fetch
there?
好吧,您正在运行“mysql_query”,将结果放入$pickass
,然后mysql_query
在结果集上再次运行。Mysql_query
(在第二行)想要一个字符串,而不是一个结果集。你不是说要去fetch
那里吗?
回答by Timon. Z
I think you would want to do something like that
我想你会想做这样的事情
$pickass = mysql_query("SELECT MAX(aid) FROM asset");
$pickassssult=mysql_result($pickass, 0);