亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHPUnit OOP 聲明

PHPUnit OOP 聲明

PHP
MM們 2023-05-12 15:56:23
我試圖了解我正在清理的代碼的 OOP 和繼承。我有一個配置文件配置.php<?php$odb_host = "localhost";$odb_name = "Prod";$odb_user = "admin";$odb_pass = "password";?>主.phpclass upSellCore{    public function ociConnect($odb_user,$odb_pass,$odb_host,$odb_name)    {        $db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$odb_host.")(PORT = 1521 )))(CONNECT_DATA=(SID=".$odb_name.")))";        $conn = oci_connect($odb_user, $odb_pass, $db);        if (!$conn) {        $e = oci_error();        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);        }        else        {            print "ERR01"; // For PHPUnit assertTrue        }    }}$sql = "Select * from users ";$upSell = new upSellCore();$upSell->ociConnect($odb_user,$odb_pass,$odb_host,$odb_name);$stid = oci_parse($upSell,$sql); // Line having issue因為我已經初始化調用 OciConnect 但是當我嘗試傳遞對象以觸發 oci_parse我收到以下錯誤:-PHP Warning:  oci_parse() expects parameter 1 to be resource, object given in /I/main.php on line 46 它$conn本身是來自 Oracle 類的對象,但是當我覆蓋我的對象 $upSell 時,我似乎無法將連接解析為 oci_parse。取自 PHPManual 的端到端而不使用 OOP<?php$conn = oci_connect('hr', 'welcome', 'localhost/XE', 'AL32UTF8');if (!$conn) {    $e = oci_error();    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);}$stid = oci_parse($conn, 'SELECT * FROM employees');oci_execute($stid);echo "<table border='1'>\n";while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {    echo "<tr>\n";    foreach ($row as $item) {        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";    }    echo "</tr>\n";}echo "</table>\n";?>
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

您不應將該類傳遞給 oci_parse 函數。它需要一個連接資源。您可以通過調用獲取資源oci_connect。在您的班級中,您的函數已經在執行此操作,因此您可以在函數中返回它。見下文。


class upSellCore

    public function ociConnect($odb_user,$odb_pass,$odb_host,$odb_name)

    {

        $db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$odb_host.")(PORT = 1521 )))(CONNECT_DATA=(SID=".$odb_name.")))";

        $conn = oci_connect($odb_user, $odb_pass, $db);


        if (!$conn) {

            $e = oci_error();

            trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

        } else {

            print "ERR01"; 

        }


        return $conn; // you need to return the connection.

    }

}

$sql = "Select * from users ";


$upSell = new upSellCore();

$conn = $upSell->ociConnect($odb_user,$odb_pass,$odb_host,$odb_name); // you get the returned connection here and use it in the following line.

$stid = oci_parse($conn, $sql); // this is expecting a resource


查看完整回答
反對 回復 2023-05-12
  • 1 回答
  • 0 關注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號