/** * function description * * @param * @return void */ public function execute() { $sql = $this->genSql(); $ret = false; Sp_Log::debug(__CLASS__ . '->' . __FUNCTION__ . ': ' . $sql); $dbh = $this->getDbh(); //var_dump($dbh); $input_parms = $this->getParams(); //var_dump($input_parms); if (is_array($input_parms) && count($input_parms) > 0) { $sth = $dbh->prepare($sql); //print_r($this->parms($sql,$input_parms));exit; if (!$sth) { Sp_Log::warning('table: ' . $this->_table_key . ',' . __CLASS__ . '->' . __FUNCTION__ . ': ' . print_r($sth->errorInfo(), true)); } $ret = $sth->execute($input_parms); if ($ret && in_array($this->_operate, array('UPDATE', 'DELETE'))) { return $sth->rowCount(); } } else { //echo $sql; $ret = $dbh->exec($sql); } if (!$ret) { Sp_Log::warning('table: ' . $this->_table_key . ',' . __CLASS__ . '->' . __FUNCTION__ . ': ' . print_r($dbh->errorInfo(), true)); } if ($ret && $this->_operate == 'INSERT' && $dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { $ret = $dbh->lastInsertId(); } return $ret; }
/** * function description * * @param * @return void */ private function getDoSth($count = false) { $sql = $this->genSql($count); Sp_Log::debug(__CLASS__ . '->' . __FUNCTION__ . ': ' . $sql); $dbh = $this->getDbh(); //var_dump($dbh); $input_parms = $this->getParams(); //var_dump($input_parms); if (is_array($input_parms) && count($input_parms) > 0) { $sth = $dbh->prepare($sql); $ret = $sth->execute($input_parms); if (!$ret) { Sp_Log::warning(__CLASS__ . '->' . __FUNCTION__ . ' execute: ' . print_r($sth->errorInfo(), true)); } } else { $sth = $dbh->query($sql); if (!$sth) { Sp_Log::warning(__CLASS__ . '->' . __FUNCTION__ . ' query: ' . print_r($dbh->errorInfo(), true)); } } if (!$sth) { Sp_Log::warning(__CLASS__ . '->' . __FUNCTION__ . ' table : ' . $this->_table . ', : ' . print_r($dbh->errorInfo(), true)); } return $sth; }