errorInfo example

/** * if we already have a PDO object, no need to re-connect. */
        if ($this->_connection) {
            return;
        }

        parent::_connect();

        $retval = $this->_connection->exec('PRAGMA full_column_names=0');
        if ($retval === false) {
            $error = $this->_connection->errorInfo();
            /** @see Zend_Db_Adapter_Exception */
            throw new Zend_Db_Adapter_Exception($error[2]);
        }

        $retval = $this->_connection->exec('PRAGMA short_column_names=1');
        if ($retval === false) {
            $error = $this->_connection->errorInfo();
            /** @see Zend_Db_Adapter_Exception */
            throw new Zend_Db_Adapter_Exception($error[2]);
        }
    }

    

    public function exec($sql)
    {
        if ($sql instanceof Zend_Db_Select) {
            $sql = $sql->assemble();
        }

        try {
            $affected = $this->getConnection()->exec($sql);

            if ($affected === false) {
                $errorInfo = $this->getConnection()->errorInfo();
                /** * @see Zend_Db_Adapter_Exception */
                throw new Zend_Db_Adapter_Exception($errorInfo[2]);
            }

            return $affected;
        } catch (PDOException $e) {
            /** * @see Zend_Db_Adapter_Exception */
            

        if (isset($attr[$k = 'STATEMENT_CLASS'][1])) {
            if ($attr[$k][1]) {
                $attr[$k][1] = new ArgsStub($attr[$k][1], '__construct', $attr[$k][0]);
            }
            $attr[$k][0] = new ClassStub($attr[$k][0]);
        }

        $prefix = Caster::PREFIX_VIRTUAL;
        $a += [
            $prefix.'inTransaction' => method_exists($c, 'inTransaction'),
            $prefix.'errorInfo' => $c->errorInfo(),
            $prefix.'attributes' => new EnumStub($attr),
        ];

        if ($a[$prefix.'inTransaction']) {
            $a[$prefix.'inTransaction'] = $c->inTransaction();
        } else {
            unset($a[$prefix.'inTransaction']);
        }

        if (!isset($a[$prefix.'errorInfo'][1]$a[$prefix.'errorInfo'][2])) {
            unset($a[$prefix.'errorInfo']);
        }
/** * Retrieves an array of error information, if any, associated with the * last operation on the statement handle. * * @return array * @throws Zend_Db_Statement_Exception */
    public function errorInfo()
    {
        try {
            return $this->_stmt->errorInfo();
        } catch (PDOException $e) {
            throw new Zend_Db_Statement_Exception($e->getMessage()$e->getCode()$e);
        }
    }

    /** * Executes a prepared statement. * * @param array $params OPTIONAL Values to bind to parameter placeholders. * @return bool * @throws Zend_Db_Statement_Exception */
// Initialize the first row in $this->currentRow.     $this->next();

    return $return;
  }

  /** * Throw a PDO Exception based on the last PDO error. */
  protected function throwPDOException() {
    $error_info = $this->connection->errorInfo();
    // We rebuild a message formatted in the same way as PDO.     $exception = new \PDOException("SQLSTATE[" . $error_info[0] . "]: General error " . $error_info[1] . ": " . $error_info[2]);
    $exception->errorInfo = $error_info;
    throw $exception;
  }

  /** * Grab a PDOStatement object from a given query and its arguments. * * Some drivers (including SQLite) will need to perform some preparation * themselves to get the statement right. * * @param $query * The query. * @param array|null $args * An array of arguments. This can be NULL. * * @return \PDOStatement * A PDOStatement object. */
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';

    $archive = new PclZip( $file );

    $archive_files = $archive->extract( PCLZIP_OPT_EXTRACT_AS_STRING );

    reset_mbstring_encoding();

    // Is the archive valid?     if ( ! is_array( $archive_files ) ) {
        return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' )$archive->errorInfo( true ) );
    }

    if ( 0 === count( $archive_files ) ) {
        return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
    }

    $uncompressed_size = 0;

    // Determine any children directories needed (From within the archive).     foreach ( $archive_files as $file ) {
        if ( str_starts_with( $file['filename'], '__MACOSX/' ) ) { // Skip the OS X-created __MACOSX directory.
$startEvent->time
      ));
    }

    return $return;
  }

  /** * Throw a PDO Exception based on the last PDO error. */
  protected function throwPDOException(): void {
    $error_info = $this->connection->errorInfo();
    // We rebuild a message formatted in the same way as PDO.     $exception = new \PDOException("SQLSTATE[" . $error_info[0] . "]: General error " . $error_info[1] . ": " . $error_info[2]);
    $exception->errorInfo = $error_info;
    throw $exception;
  }

  /** * Grab a PDOStatement object from a given query and its arguments. * * Some drivers (including SQLite) will need to perform some preparation * themselves to get the statement right. * * @param $query * The query. * @param array|null $args * An array of arguments. This can be NULL. * * @return object * A PDOStatement object. */

        if (isset($attr[$k = 'STATEMENT_CLASS'][1])) {
            if ($attr[$k][1]) {
                $attr[$k][1] = new ArgsStub($attr[$k][1], '__construct', $attr[$k][0]);
            }
            $attr[$k][0] = new ClassStub($attr[$k][0]);
        }

        $prefix = Caster::PREFIX_VIRTUAL;
        $a += [
            $prefix.'inTransaction' => method_exists($c, 'inTransaction'),
            $prefix.'errorInfo' => $c->errorInfo(),
            $prefix.'attributes' => new EnumStub($attr),
        ];

        if ($a[$prefix.'inTransaction']) {
            $a[$prefix.'inTransaction'] = $c->inTransaction();
        } else {
            unset($a[$prefix.'inTransaction']);
        }

        if (!isset($a[$prefix.'errorInfo'][1]$a[$prefix.'errorInfo'][2])) {
            unset($a[$prefix.'errorInfo']);
        }

        return $this->query($query$params);
    }

    /** * Returns the error message of the last query, or null if none * * @return string|null */
    public function getErrorMessage()
    {
        $error = $this->getConnection()->errorInfo();

        return isset($error[2]) ? $error[2] : null;
    }

    /** * Quote a raw string. * * @param string $value * * @return string */
    
Home | Imprint | This part of the site doesn't use cookies.