doujindou4356 2014-01-06 09:39
浏览 80
已采纳

PDO未定义的功能

I have this class:

<?php
    class LLPDO extends PDO{

         public function __construct($dsn, $user, $pass, $options = array()){
            $this->link = parent::__construct($dsn, $user, $pass, $options);
            $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }

        public function isConnected(){
             try {
                $this->link->query('SELECT 1+1');
            } catch (PDOException $e) {
                return false;
            }
            return true;
        }

    }
?>

But when I make a call like so:

if(!$ibdb.isConnected()){
    $ibdb = new LLPDO(connectionString2($ini['ibdbn'], $ini['ibdbclient'], $ini['ibdbport']), $ini['ibdbusr'], $ini['ibdbpass'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}

I get a Fatal error: Call to undefined function isConnected(). Am I calling the function wrong? Or did I do something incorrect in the class file? $ibdb was created ahead of time earlier in the script I'm running it in.

  • 写回答

2条回答 默认 最新

  • dotwc62080 2014-01-06 09:41
    关注

    Methods are called through the -> operator:

    if(!$ibdb->isConnected()){
        $ibdb = new LLPDO(connectionString2($ini['ibdbn'], $ini['ibdbclient'], $ini['ibdbport']), $ini['ibdbusr'], $ini['ibdbpass'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部