php 警告:mysql_fetch_row() 期望参数 1 是资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7113310/
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_fetch_row() expects parameter 1 to be resource
提问by ipengineer
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
I am receiving the below message when I run this script:
运行此脚本时,我收到以下消息:
Warning: mysql_fetch_row() expects parameter 1 to be resource, string given in /var/www/html/toolkit/routing.php on line 12
警告:mysql_fetch_row() 期望参数 1 是资源,字符串在第 12 行的 /var/www/html/toolkit/routing.php 中给出
I have ran the query in the mysql console and it prints the correct row. Not sure why I cant get it to show up in php?
我在 mysql 控制台中运行了查询,它打印了正确的行。不知道为什么我不能让它显示在 php 中?
routing.php page:
routing.php 页面:
<?php
error_reporting(E_ALL);
////error_reporting(0);
ini_set('display_errors', 'On');
include("db/sbc_config.php");
include("db/mysql.class.php");
$db = new MySQL(true, DB_DATABASE_ROUTING, DB_SERVER, DB_USER , DB_PASS);
if ($db->Error()) $db->Kill();
$searchroute = "SELECT * FROM destination_route as d WHERE d.destPrefix='2146811'";
$result = mysql_fetch_row($searchroute);
echo $result;
?>
sbc_config.php:
sbc_config.php:
<?php
//database server
define('DB_SERVER', "10.10.1.146");
//database login name"
define('DB_USER', "user");
//database login password
define('DB_PASS', "pasword");
//database names
define('DB_DATABASE_ROUTING', "routing");
//smart to define your table names also
define('TABLE_DESTINATION_ROUTE', "destination_route");
?>
回答by Etienne de Martel
mysql_fetch_row
takes a cursor and returns the next row in that cursor. You're trying to give it a string. You're missing a step.
mysql_fetch_row
接受一个游标并返回该游标中的下一行。你试图给它一个字符串。你少了一步。
You'll have to execute that query first:
您必须先执行该查询:
$cursor = mysql_query($searchroute); // for example
$result = mysql_fetch_row($cursor);
回答by Arnaud Le Blanc
You have to execute the query before you can fetch results:
您必须先执行查询,然后才能获取结果:
$searchroute = "SELECT * ...";
$results = mysql_query($searchroute);
$row = mysql_fetch_row($results);
回答by Nick Shaw
mysql_fetch_row must be called after mysql_query, you can't pass the query into the fetch row - see PHP Manual
mysql_fetch_row 必须在 mysql_query 之后调用,您不能将查询传递到 fetch 行中 - 请参阅PHP 手册
回答by Marc B
$db = new MySQL(true, DB_DATABASE_ROUTING, DB_SERVER, DB_USER , DB_PASS);
is that supposedto be MySQLi? The mysql_*() functions do not have an OOP interface. You'd be mising mysqli and mysql calls, which is not supported. They're completely independent of each other internally, and a db handle or result statement from one is NOT useable in the other.
那应该是 MySQLi 吗?mysql_*() 函数没有 OOP 接口。你会错过 mysqli 和 mysql 调用,这是不支持的。它们在内部完全独立,一个的 db 句柄或结果语句不能用于另一个。