English 中文(简体)
我无法从数据库中看到数据( 提供的论点不有效) [ 已关闭]
原标题:I can t see data from database (supplied argument is not a valid) [closed]
  • 时间:2012-05-24 15:11:25
  •  标签:
  • php
  • mysql

I can t understand why i get supplied argument is not a valid? My codes belove

db connect.class.php http://ideone.com/AILC9

http://ideone.com/wIbL3" rel="nofollow" >http://ideone.com/wIbL3

http://ideone.com/OQSg9” rel=“no follow”>http://ideone.com/OQSg9

index.php http://ideone.com/Zp6sF

当我运行索引.php,我可以得到这个代码:

<html>

 <head>

  <title>   <br />
<b>Warning</b>:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in <b>C:AppServwwwilkclassgetdata.class.php</b> on line <b>21</b><br />
  </title>

  <meta name="description" content="<br />
<b>Warning</b>:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in <b>C:AppServwwwilkclassgetdata.class.php</b> on line <b>21</b><br />
" />

  <meta name="keywords" content="<br />
<b>Warning</b>:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in <b>C:AppServwwwilkclassgetdata.class.php</b> on line <b>21</b><br />
" />

 </head>

</html>
最佳回答

您的 Mysql 连接/ 请求失败 。 在每次拨打信头以显示错误后, < code> echo mysql_ error ()

同样在您的 sayfa Header () 方法中,最后两行将永远无法执行,因为您有两行返回, 一旦您 return 功能执行结束, 就会有两行返回 。

问题回答

在您的数据库连接类中,您没有检查连接本身是否已经建立。 此错误显示没有建立有效的 Mysql 连接, 因此该变量没有附加资源 。 您可能没有错误, 因此您应该总是退出/ 中止, 如果您的连接 = 无效。 请确认您的数据库证书正确 。

将函数更改为此

protected function getData()
{
    $result = mysql_query($this->sql, $this->database) or $this->error = mysql_error();
    if($result !== false) die(mysql_error());

    while($rs = mysql_fetch_assoc($result))
    {
        $this->data[] = $rs;
    }
    $dataObject = (object) $this->data;
    return (array) $this->data;
}

它会返回一个错误, 错误会告诉您查询有什么问题





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签