duanhuang2150 2015-11-15 19:55
浏览 86
已采纳

调用未定义的方法PDOStatement

I'm having this error and been trying to figure whats wrong for like 3 days straight with no luck:

Fatal error: Call to undefined method PDOStatement::bindValues() on line 92

My complete code

<?php
//CLASS TO HANDLE AD

class Ad
{
    //Ad id from database
    public $id = null;

    //Ad client
    public $client = null;

    //Ad client login id
    public $client_loginID = null;

    //Ad video source
    public $video = null;

    //Ad banner source
    public $banner = null;

    //Ad cover source
    public $cover = null;

    //Ad mid video banner ad
    public $midVideoBannerAd = null;

    //Ad link
    public $link = null;

    //Ad click
    public $clicks = null;

    //Ad impressions
    public $impressions = null;

    //If ad is active
    public $active = null;

    //Sets the obect properties using the values in supplied array
    public function __construct( $data=array() ){
        if( isset ( $data['id'] ) ) $this->id = (int) $data['id'];
        if( isset ( $data['client'] ) ) $this->client = $data['client']; 
    }

    //Sets the object properties using the edit form post values in the supplied array
    public function storeFormValues( $params ){

        //Store all the parameters
        $this->__construct( $params );
    }

    //Returns an Author Object matching the given id
    public static function getById( $statement ){
        $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        $sql = "SELECT * FROM ad $statement";
        $st = $conn->prepare( $sql );
        $st->execute();
        $row = $st->fetch();
        $conn = null;
        if( $row ) return new Ad( $row );
    }

    //Returns all (or range of) ad object in the db
    public static function getList( $statement ){
        $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        $sql = "SELECT * FROM ad $statement";
        $st = $conn->prepare( $sql );
        $st->execute();
        $list = array();

        while( $row = $st->fetch() ){
            $ad = new Ad( $row );
            $list[] = $ad;
        }

        //Now get the total number of Ad that match the criteria
        $sql = "SELECT FOUND_ROWS() AS totalRows";
        $totalRows = $conn->query( $sql )->fetch();
        $conn = null;
        return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
    }

    //Insert current Ad object into database and set its ID properties
    public function insert(){

        //Check if Ad object already has an id

        //Insert the Ad
        $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        $sql = "INSERT INTO ad (client) VALUES ( :client )";
        $st = $conn->prepare( $sql );
        $st->bindValues( ":client", $this->client, PDO::PARAM_STR );

        $st->execute();
        $this->id = $conn->lastInsertId();
        $conn = null;
    }

    //Updates the current Ad in DB
    public function update(){

        //Check if Ad object has an id  
        if( !is_null ( $this->id ) ) trigger_error ( "Ad::update(): Attempt to update an Ad object that already has an ID set.", E_USER_ERROR );

        //Updates the Ad
        $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        $sql = "UPDATE ad set client=:client, client_loginID=:client_loginID, video=:video, midVideoBannerAd=:midVideoBannerAd, banner=:banner, cover=:cover, link=:link, active=:active WHERE id=:id";
        $st = $conn->prepare( $sql );
        $st->bindValues( ":client", $this->client, PDO::PARAM_STR );
        $st->bindValues( ":client_loginID", $this->client_loginID, PDO::PARAM_INT );
        $st->bindValues( ":video", $this->video, PDO::PARAM_INT );
        $st->bindValues( ":midVideoBannerAd", $this->midVideoBannerAd, PDO::PARAM_INT );
        $st->bindValues( ":banner", $this->banner, PDO::PARAM_INT );
        $st->bindValues( ":cover", $this->cover, PDO::PARAM_INT );
        $st->bindValues( ":link", $this->link, PDO::PARAM_STR );
        $st->bindValues( ":active", $this->active, PDO::PARAM_INT );
        $st->bindValues( ":id", $this->id, PDO::PARAM_INT );
        $st->execute();
        $conn = null;
    }

    //Delete current Ad from Database
    public function delete(){

        //Delete the Ad
        $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        $st = $conn->prepare( "DELETE FROM ad WHERE id=:id" );
        $st->bindValues( ":id", $this->id, PDO::PARAM_INT );
        $st->execute();
        $conn = null;
    }
}

And this is what's on line 92:

    $st->bindValues( ":client", $this->client, PDO::PARAM_STR );
  • 写回答

1条回答 默认 最新

  • douhuai2015 2015-11-15 20:01
    关注

    The method is called PDOStatement->bindValue() without the trailing "s" see http://www.php.net/manual/en/pdostatement.bindvalue.php

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

报告相同问题?

悬赏问题

  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要