我遇到了这个错误,并试图在3天内没有运气的情况下弄错了什么:
致命错误:在第92行调用未定义的方法PDOStatement :: bindValues()
我的完整代码
<?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;
}
}
这就是第92行:
$st->bindValues( ":client", $this->client, PDO::PARAM_STR );
答案 0 :(得分:4)
该方法称为PDOStatement-&gt; bindValue(),不带尾随“s” 见http://www.php.net/manual/en/pdostatement.bindvalue.php