Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 8.1 #41

Closed
parsibox opened this issue Mar 4, 2022 · 9 comments
Closed

php 8.1 #41

parsibox opened this issue Mar 4, 2022 · 9 comments

Comments

@parsibox
Copy link

parsibox commented Mar 4, 2022

hi
dear we have too many fatal error on php 8.1


Deprecated: Return type of PDOOCI\PDO::beginTransaction() should either be compatible with PDO::beginTransaction(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 256

Deprecated: Return type of PDOOCI\PDO::commit() should either be compatible with PDO::commit(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 234

Deprecated: Return type of PDOOCI\PDO::errorCode() should either be compatible with PDO::errorCode(): ?string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 306

Deprecated: Return type of PDOOCI\PDO::errorInfo() should either be compatible with PDO::errorInfo(): array, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 319

Deprecated: Return type of PDOOCI\PDO::exec($sql) should either be compatible with PDO::exec(string $statement): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 164

Deprecated: Return type of PDOOCI\PDO::getAttribute($attr) should either be compatible with PDO::getAttribute(int $attribute): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 205

Deprecated: Return type of PDOOCI\PDO::getAvailableDrivers() should either be compatible with PDO::getAvailableDrivers(): array, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 370

Deprecated: Return type of PDOOCI\PDO::inTransaction() should either be compatible with PDO::inTransaction(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 384

Deprecated: Return type of PDOOCI\PDO::lastInsertId($sequence = null) should either be compatible with PDO::lastInsertId(?string $name = null): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 413

Deprecated: Return type of PDOOCI\PDO::prepare($query, $options = null) should either be compatible with PDO::prepare(string $query, array $options = []): PDOStatement|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 270

Fatal error: Declaration of PDOOCI\PDO::query($statement, $mode = null, $p1 = null, $p2 = null) must be compatible with PDO::query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs): PDOStatement|false in D:\wamp64\www\product\ussd\ussd-oracle\core\pdooci\PDO.php on line 141
@taq
Copy link
Owner

taq commented Mar 7, 2022

Could you please provide a patch?

@parsibox
Copy link
Author

parsibox commented Mar 8, 2022

i will wokr it
but it may be take 2 or 3 month

@taq
Copy link
Owner

taq commented Mar 8, 2022

No problem, @parsibox . I don't even use PHP or Oracle for years. I'll declare this project as abandonware. If you want to fork it, fell free to do it.

@cwolcott
Copy link

@parsibox have you found an alternative or worked your way through fixing issues? We are heavily integrated with this package. Curious on your thoughts.

@parsibox
Copy link
Author

no

@cwolcott
Copy link

@parsibox thanks for the responsive. I will document over the next couple of weeks our migration from PHP 7.4.x to PHP 8.1.x and how me are handling the interface to Oracle. A couple of initial notes:

When upgrading from PHP 7.4.27 to PHP 8.1.4 the OCI8 extension was update:

  • PHP 7.4.27 OCI8 - v2.2.0 [Oracle Run-time 12.2.0.1.0]
  • PHP 8.1.5 OCI8 - v3.1.0 [Oracle Run-time 19.9.0.0.0]

The PDO_OCI is no longer experimental. It was folded into the PHP Core while ago. Here is a recent blog about OCI8 and PDO_OCI. We will attempt to install the extension and see how it integrates into our code.

@taq
Copy link
Owner

taq commented Apr 11, 2022

@cwolcott so, finally now PDO_OCI is working without workarounds? Very good! I just created this package to make it easier to work with PHP and Oracle, but as mentioned, I don't use both for years ... so we can officially mark this package as no longer needed? :-)

@cwolcott
Copy link

@taq, I would go that far yet. PDO_OCI is part of the core rather than community support via PECL. I have not tested it yet. I will report back over the next couple of weeks.

@parsibox
Copy link
Author

parsibox commented Apr 7, 2023

<?php
class OraclePDO extends \PDO {

    public function __construct(string $dsn, string $username, string $password, array $options = []) {
        $conn = oci_connect($username, $password, $dsn);
        if (!$conn) {
            throw new \PDOException("Could not connect to database");
        }
        $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
    }

    public function prepare(string $statement, array $driver_options = []) : \PDOStatement {
        $stmt = oci_parse($this->conn, $statement);
        if (!$stmt) {
            throw new \PDOException("Could not prepare statement");
        }
        return new OraclePDOStatement($stmt);
    }

    public function exec(string $statement) : int {
        $stmt = oci_parse($this->conn, $statement);
        if (!$stmt) {
            throw new \PDOException("Could not prepare statement");
        }
        if (!oci_execute($stmt)) {
            throw new \PDOException("Could not execute statement");
        }
        $rows = oci_num_rows($stmt);
        oci_free_statement($stmt);
        return $rows;
    }

    public function query(string $statement, int $fetch_style = \PDO::FETCH_BOTH, mixed ...$fetch_args) : \PDOStatement|bool {
        $stmt = oci_parse($this->conn, $statement);
        if (!$stmt) {
            throw new \PDOException("Could not prepare statement");
        }
        if (!oci_execute($stmt)) {
            throw new \PDOException("Could not execute statement");
        }
        return new OraclePDOStatement($stmt);
    }

}

class OraclePDOStatement extends \PDOStatement {

    private $stmt;

    public function __construct($stmt) {
        $this->stmt = $stmt;
    }

    public function execute(array $input_parameters = []) : bool {
        foreach ($input_parameters as $key => $value) {
            oci_bind_by_name($this->stmt, ":$key", $value);
        }
        return oci_execute($this->stmt);
    }

    public function fetch(int $fetch_style = \PDO::FETCH_BOTH, int $cursor_orientation = \PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) : mixed {
        switch ($fetch_style) {
            case \PDO::FETCH_BOTH:
                return oci_fetch_array($this->stmt, OCI_BOTH);
            case \PDO::FETCH_NUM:
                return oci_fetch_array($this->stmt, OCI_NUM);
            case \PDO::FETCH_ASSOC:
                return oci_fetch_assoc($this->stmt);
            case \PDO::FETCH_OBJ:
                return oci_fetch_object($this->stmt);
            default:
                throw new \PDOException("Unsupported fetch style");
        }
    }

    public function rowCount() : int {
        return oci_num_rows($this->stmt);
    }

    public function fetchColumn(int $column_number = 0) : mixed {
        $row = oci_fetch_array($this->stmt, OCI_NUM);
        return $row[$column_number];
    }

    public function bindValue(mixed $parameter, mixed $value, int $data_type = \PDO::PARAM_STR) : bool {
        return oci_bind_by_name($this->stmt, $parameter, $value);
    }

}



// Example for SELECT query
try {
    $db = new OraclePDO('oci:dbname=//localhost:1521/mydb', 'myuser', 'mypassword');
    $stmt = $db->prepare('SELECT * FROM mytable WHERE name = :name');
    $stmt->execute(['name' => 'John']);
    while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
        echo $row['id'] . ' ' . $row['name'] . "\n";
    }
} catch (\PDOException $e) {
    echo $e->getMessage();
}

// Example for INSERT query
try {
    $db = new OraclePDO('oci:dbname=//localhost:1521/mydb', 'myuser', 'mypassword');
    $stmt = $db->prepare('INSERT INTO mytable (name, age) VALUES (:name, :age)');
    $stmt->execute(['name' => 'Jane', 'age' => 25]);
    $rowCount = $stmt->rowCount();
    echo $rowCount . ' rows inserted.';
} catch (\PDOException $e) {
    echo $e->getMessage();
}

// Example for UPDATE query
try {
    $db = new OraclePDO('oci:dbname=//localhost:1521/mydb', 'myuser', 'mypassword');
    $stmt = $db->prepare('UPDATE mytable SET age = :age WHERE name = :name');
    $stmt->execute(['name' => 'John', 'age' => 30]);
    $rowCount = $stmt->rowCount();
    echo $rowCount . ' rows updated.';
} catch (\PDOException $e) {
    echo $e->getMessage();
}

// Example for DELETE query
try {
    $db = new OraclePDO('oci:dbname=//localhost:1521/mydb', 'myuser', 'mypassword');
    $stmt = $db->prepare('DELETE FROM mytable WHERE id = :id');
    $stmt->execute(['id' => 3]);
    $rowCount = $stmt->rowCount();
    echo $rowCount . ' rows deleted.';
} catch (\PDOException $e) {
    echo $e->getMessage();
}

?>

@taq taq closed this as completed Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants