简体   繁体   English

调用未定义的方法PDOStatement

[英]Call to undefined method PDOStatement

I'm having this error and been trying to figure whats wrong for like 3 days straight with no luck: 我遇到此错误,并试图连续3天找出问题出在哪里,但没有运气:

Fatal error: Call to undefined method PDOStatement::bindValues() on line 92 致命错误:在第92行调用未定义的方法PDOStatement :: bindValues()

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: 这是第92行上的内容:

    $st->bindValues( ":client", $this->client, PDO::PARAM_STR );

该方法称为PDOStatement-> bindValue(),后缀“ s”,请参见http://www.php.net/manual/en/pdostatement.bindvalue.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM