-4
您将不得不为get.class.php提供帮助。相同的代码,但不工作之一?
工作情况(的index.php面条):意大利面条的
<?php
require_once 'classes/get.class.php';
$get = new Get();
$get->getSql("SELECT * FROM gunler ORDER BY g_id ASC LIMIT 0,15");
foreach($get->getData() as $data)
{
echo $data["g_name"];
}
?>
结果:
18 January 2012
的成功感。
不工作的情况下:这
<?php
require_once 'get.class.php';
Class Main Extends Get
{
function __construct()
{
// boş
}
public function getGun($limit = 15, $sayfa = 1)
{
$limit1 = $limit * ($sayfa - 1);
$limit2 = $limit1 + $limit;
parent::getSql("SELECT * FROM gunler ORDER BY g_id ASC LIMIT " . $limit1 . "," . $limit2);
return parent::getData();
}
}
?>
$main = new Main();
print_r($main->getGun());
结果:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\dailypremium\classes\get.class.php on line 39
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\dailypremium\classes\get.class.php on line 55
Array ()
我不能看到第二码之间的差额第一守则。哪里有问题?
试图在您的Main :: __构造()中添加'parent :: __ construct()'? – 2012-01-18 13:20:31
这就是你没有正确建立mysql连接时得到的错误 - 或者是无意中为你的mysql查询函数提供了一个null(非mysql连接)值。没有我认为的DB脚本的代码很难说更多。 – Cole 2012-01-18 13:20:52
与你的问题无关,但看着你的Get类,通常做一些事情,比如在'getSql()'调用中设置'$ this-> sql',然后依靠你的'Query() '。明确你的方法对名称所做的事情总是好得多,而不是依赖于内在的隐藏的怪癖。作为一个例子,如果你的'Query()'从你的'getSql()'中获得了sql,那么这将会是一个更好的设计。 – jprofitt 2012-01-18 13:24:09