Kaedah oci_parse() mengembalikan kaedah penghuraian nol
P粉043432210
P粉043432210 2024-01-29 13:46:11
0
1
390

Saya ingin mencipta kelas yang menyambung ke pangkalan data ORACLE menggunakan beberapa kaedah OCI.

Tetapi apabila saya memanggil kaedah Parse() ia adalah batal dan kaedah FetchArray() saya tidak mengembalikan apa-apa

Kelas PHP pangkalan data:

class Database
{
    /**
     * @var string
     */
    private string $login;
    /**
     * @var string
     */
    private string $password;
    /**
     * @var string
     */
    private string $description;
    /**
     * @var
     */
    private $connection;
    /**
     * @var
     */
    private $stmt;

    public function __construct(string $login, string $password, string $description)
    {
        $this->login = $login;
        $this->password = $password;
        $this->description = $description;
    }


    public function Connection($character_set = null, $session_mode = null)
    {
        $this->connection = oci_connect($this->login, $this->password, $this->description, $character_set,    $session_mode);
    }

   
    public function Parse(string $sql)
    {
        $this->stmt = oci_parse($this->connection, $sql);
    }


    public function Execute()
    {
        oci_execute($this->stmt);
    }

Ujian halaman.php:

$database = new Database($login, $pass, $descr);
        $database->Connection();
        if ($database->IsConnected()) {
            $database->Parse($sql);
            $database->Execute();
            while ($row = $database->FetchArray(OCI_BOTH) != false) {
                // Use the uppercase column names for the associative array indices
                echo $row[0] . " and " . $row['EMAIL']   . " are the same<br>\n";
                echo $row[1] . " and " . $row['NAME'] . " are the same<br>\n";
            }
            $database->Disconnection();
        } else {
            echo 'Error';
        }

Sambungan pangkalan data kini berjaya.

Dapatkan kaedah tatasusunan:

public function FetchArray($mode = null)
    {
        oci_fetch_array($this->stmt, $mode);
    }

P粉043432210
P粉043432210

membalas semua(1)
P粉571233520

Saya rasa saya jumpa masalah. Dalam keadaan sementara anda, anda mungkin telah terlepas beberapa kurungan untuk menjadikannya membandingkan hasil mendapatkan data baris dengan nilai boolean palsu.

$database = new Database($login, $pass, $descr);
        $database->Connection();
        if ($database->IsConnected()) {
            $database->Parse($sql);
            $database->Execute();
            while (($row = $database->FetchArray(OCI_BOTH)) != false) {
                // Use the uppercase column names for the associative array indices
                echo $row[0] . " and " . $row['EMAIL']   . " are the same<br>\n";
                echo $row[1] . " and " . $row['NAME'] . " are the same<br>\n";
            }
            $database->Disconnection();
        } else {
            echo 'Error';
        }

Baris ini telah dikemas kini:

while (($row = $database->FetchArray(OCI_BOTH)) != false) {

Saya rasa ia juga selamat untuk mengeluarkan penukaran jenis daripada fungsi get

public function FetchArray($mode = null):
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan