-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