public function insertPDO($table, array $data = array())
    {
        if (count($data) === 0) {
            return false;
        }
        $q = "INSERT INTO `$table` ";
        $v = '';
        $n = '';

        foreach ($data as $key => $val) {
            $n .= "`$key`, ";
            if (strtolower($val) === 'now()') {
                $v .= 'NOW(), ';
                unset($data[$key]);
            } else {
                $v .= '?, ';
            }
        }
        $q .= '(' . rtrim($n, ', ') . ') VALUES (' . rtrim($v, ', ') . ');';
        try {
            $this->_queryId = self::$_linkId->prepare($q);

            $i = 1;
            foreach ($data as $key => $val) {
                $type = $this->getPDOConstantType($val);
                $this->_queryId->bindValue($i, $val, $type);
                ++$i;
            }
            $this->_queryId->execute();
            return self::$_linkId->lastInsertId();
        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            return false;
        }
    }
public function insertPDO($table, array $data = array())
    {
        if (count($data) === 0) {
            return false;
        }
        $q = "INSERT INTO `$table` ";
        $v = '';
        $n = '';

        foreach ($data as $key => $val) {
            $n .= "`$key`, ";
            if (strtolower($val) === 'now()') {
                $v .= 'NOW(), ';
                unset($data[$key]);
            } else {
                $v .= '?, ';
            }
        }
        $q .= '(' . rtrim($n, ', ') . ') VALUES (' . rtrim($v, ', ') . ');';
        try {
            $this->_queryId = self::$_linkId->prepare($q);

            $i = 1;
            foreach ($data as $key => $val) {
                $type = $this->getPDOConstantType($val);
                $this->_queryId->bindValue($i, $val, $type);
                ++$i;
            }
            $this->_queryId->execute();
            return self::$_linkId->lastInsertId();
        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            return false;
        }
    }
public function insertPDO ( $ table , array $ data = array ( ) ) { if ( count ( $ data ) === 0 ) { return false ; } $ q = "INSERT INTO `$table` " ; $ v = '' ; $ n = '' ; foreach ( $ data as $ key => $ val ) { $ n .= "`$key`, " ; if ( strtolower ( $ val ) === 'now()' ) { $ v .= 'NOW(), ' ; unset ( $ data [ $ key ] ) ; } else { $ v .= '?, ' ; } } $ q .= '(' . rtrim ( $ n , ', ' ) . ') VALUES (' . rtrim ( $ v , ', ' ) . ');' ; try { $ this -> _queryId = self :: $ _linkId -> prepare ( $ q ) ; $ i = 1 ; foreach ( $ data as $ key => $ val ) { $ type = $ this -> getPDOConstantType ( $ val ) ; $ this -> _queryId -> bindValue ( $ i , $ val , $ type ) ; ++ $ i ; } $ this -> _queryId -> execute ( ) ; return self :: $ _linkId -> lastInsertId ( ) ; } catch ( PDOException $ e ) { $ this -> _error = $ e -> getMessage ( ) ; return false ; } }
Does an insert query with an array for data.
@access public
@param String $table
@param Array $data is an assoc array with keys are column names and values as the actual values
@return Mixed Returns ID of the inserted record or FALSE on failure.
Does an insert query with an array for data .