我有一個PHP編程的序列順序,我需要從表中查詢並將其插入到JSON數組中。我不知道我的錯誤在哪裏,但它只是沒有通過。請幫幫我,從PHP函數查詢JSON
在dbinfo.inc.php,
define("ORA_CON_UN", "ADMIN");
define("ORA_CON_PW", "pass");
define("ORA_CON_DB", "192.168.100.195/finance");
class db {
private $conn;
private $lastId;
private static $instance;
private function _construct(){
$this->connect();
}
public static function create(){
if (!isset(self::$instance)) {
self::$instance = new db();
}
return self::$instance;
}
public function connect($dbconn = ORA_CON_DB, $dbuser = ORA_CON_UN, $dbpass = ORA_CON_PW){
$this->conn = oci_connect($dbuser, $dbpass, $dbconn);
}
}
和DBFunction.php
include 'dbinfo.inc.php';
class Connection{
private $dbConnection;
public function _construct($dbConnection){
$this->dbConnection = $dbConnection;
}
function initConnection(){
$db = new db();
$dbConnection = $db->connect();
}
}
class PurchaseOrder {
private $job = '%';
private $subjob = '%';
public function _construct($job, $subjob){
$this->job = $job;
$this->subjob = $subjob;
}
function listPO($job, $subjob){
$conn = new Connection();
$conn->initConnection();
$sql = oci_parse($conn, 'SELECT VPI.PO_NO FROM [email protected]_WENLOGINV_LINK WHERE VPI.PROJECT_NO = ' .$job. ' AND VPI.PROJECT_NAME = ' .$subjob);
if (!$conn) {
$oerr = OCIError($conn);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
exit();
} else {
echo 'CONNECTION SUCCEDED';
}
$rows = array();
while ($r = oci_fetch_assoc($sql)){
$rows[] = $r;
}
$listPO = json_encode($rows);
oci_execute($sql);
oci_close($conn);
}
}
;最後,testDBFunction.php
include('DBFunction.php');
$queryOracle = new PurchaseOrder();
$queryOracle->listPO('W-IGG','');
var_dump($queryOracle);
,這是我的錯誤訊息,
警告:oci_parse()需要參數1爲資源,對象爲第36行的C:\ xampp \ htdocs \ WeltesFinance \ pages \ lib \ DBFunction.php 是資源,在 ç空給出:\ XAMPP \ htdocs中\ WeltesFinance \頁面\ lib中\ DBFunction.php在線47上
警告:oci_execute()預計參數1是資源,在C空給出 :\對象(PurchaseOrder)#1(2){[「job」:「PurchaseOrder」:private] => string(1)「%」[「}」 subjob「:」PurchaseOrder「:private] => string(1)」%「}
我不知道到底哪裏我的錯誤是,請幫我
IM仍然有同樣的錯誤 –
還是一樣的錯誤..也許弄錯somwhere別的? –
我對答案進行了更新。我改變了你的初始'db'類。另外請注意,你並不需要對連接類進一步包裝。詳情請參閱評論。 –