doushou6480 2012-01-18 13:17
浏览 45
已采纳

相同的代码,但不是两个中的一个?

You will have to get.class.php for giving help.

Working case(index.php spaghetti):

<?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"];
}
?>

result of spaghetti:

18 January 2012

the successful in a sense.

Are not working case:

<?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());

result of this:

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 ( )

I can't see any difference first codes between second codes. Where is the problem?

  • 写回答

1条回答 默认 最新

  • douxi6903 2012-01-18 13:20
    关注

    This is likely happening because you are not calling parent::__construct() in your overridden constructor and your database connection is never created.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图