php 警告:mysql_fetch_object():提供的参数不是有效的 MySQL 结果资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3923101/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:28:03  来源:igfitidea点击:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource

phpmysqlhtml

提问by DonJuma

Hell there when i try and connect to pull thing out of the database i get the following error:

地狱当我尝试连接以从数据库中提取东西时,我收到以下错误:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/content/49/5548763/html/matt/download.php on line 17

None of the other answers on this site worked.

本网站上的其他答案均无效。

here is the script:

这是脚本:

<?php

$con = mysql_connect("XXXX", "name", "password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("nameofdb",$con);

$musictable = "";

$sql = "GET * FROM matt";

$result = mysql_query($sql,$con);

while($row = mysql_fetch_object($result)) {

$id = $row->id;

$name = $row->name;

$update = $row->update;

$length = $row->length;

$size = $row->size;

$musictable .= "
  <tr>
    <td width=\"63%\">".$name."</td>
    <td width=\"10%\">".$length." / ".$size."</td>
    <td width=\"10%\"><a href=\"download.php?mp3=".$name."\">DOWLOAD</a></td>
    <td width=\"17%\">|||||</td>
  </tr>
  ";
}

?>

回答by Pekka

That's because your query is wrong.

那是因为你的查询是错误的。

$sql = "GET * FROM matt";

must probably become

可能必须成为

$sql = "SELECT * FROM matt";

the basic measure to get warned about this is

获得警告的基本措施是

if (!$result)
 die("mySQL error: ". mysql_error());  

after issuing a query.

发出查询后。

回答by mrjames

Perhaps try using 'SELECT' instead of 'GET'?

也许尝试使用“SELECT”而不是“GET”?

回答by Fanis Hatzidakis

$sql = "GET * FROM matt";

is wrong. Correct SQL syntax is

是错的。正确的 SQL 语法是

$sql = "SELECT * FROM matt";

That error is passed into

该错误被传递到

$result = mysql_query($sql,$con);

$result = mysql_query($sql,$con);

which then is invalid and can't be used in while($row = mysql_fetch_object($result)).

然后是无效的,不能在while($row = mysql_fetch_object($result)).

You should check for mysql_error()after mysql_query()to catch these.

你应该检查mysql_error()之后mysql_query()才能捕捉到这些。

回答by Explosion Pills

Want to use SELECT *

想使用 SELECT *

You can also use

你也可以使用

mysql_query($sql, $con) or die("Error in $sql:" . mysql_error($con));

If you don't want to use die() then you can use echo to see what the error was and help debug the application at least.

如果您不想使用 die(),那么您可以使用 echo 查看错误是什么,并至少帮助调试应用程序。