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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?