警告:mysql_error():提供的参数不是有效的MySQL-Link资源 [英] Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource
问题描述
Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
$err = mysql_query("INSERT INTO tridy (id,NazevTridy,url) VALUES (
'$i',
'$tridy->find('div[class=rozvrhseznam]', 0)->find('a[href]', $i)->outertext',
'$tridy->find('div[class=rozvrhseznam]', 0)->find('a[href]', $i)->href')");
mysql_error($err); // line 97
警告:mysql_error():在第97行的/hosting/www/cran-web.com/www/rozvrh/engine.php中提供的参数不是有效的MySQL-Link资源
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /hosting/www/cran-web.com/www/rozvrh/engine.php on line 97
---第2-6行:
$username="*****.com";
$password="*********";
$database="*********";
mysql_connect('127.0.0.1', $username, $password) or die('Could not connect'.mysql_error());
mysql_select_db($database) or die( "Cannot select db.");
当我尝试执行查询时遇到此错误.您能告诉我错误消息是什么意思以及如何解决吗?
I'm getting this error when I try to execute my query. Can you tell what does the error message mean and how to fix it?
推荐答案
mysql_error()
需要链接资源",而没有结果资源".正确的方法是这样的:
mysql_error()
expects a "Link resource" and no "result resource". Te correct way would be something like:
$username="*****.com";
$password="*********";
$database="*********";
$connection = mysql_connect('127.0.0.1', $username, $password) or die('Could not connect'.mysql_error());
mysql_select_db($database, $connection) or die( "Cannot select db.");
$err = mysql_query("INSERT INTO tridy (id,NazevTridy,url) VALUES (
'$i',
'$tridy->find('div[class=rozvrhseznam]', 0)->find('a[href]', $i)->outertext',
'$tridy->find('div[class=rozvrhseznam]', 0)->find('a[href]', $i)->href')", $connection);
mysql_error($connection); // line 97
请注意使用$connection
. $ connection的Wile可以像在
Mind the use of $connection
. Wile $connection could be dropped everywhere as in
mysql_error();
默认使用哪个上次打开的连接或打开一个新的连接.虽然取决于默认连接是坏的.您可能还想研究 mysqli 或 PDO 作为与MySQL通讯的替代方法.
Which uses the last opened connection or opens a new one by default. While depending on the default connection is bad. You might also want to look into mysqli or PDO as alternative ways to talk to MySQL.
这篇关于警告:mysql_error():提供的参数不是有效的MySQL-Link资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!