PHP에서 oracle sql 문을 실행하기위한 클래스를 만들려고합니다. 여기 PHP를 사용하여 Oracle 데이터베이스에서 데이터를 가져 오는 방법
내가 내 기능<?php
include "dbaseconn/dbcontrol.php";
$DbControl = new DbControl;
$DbControl->execute(" SELECT * FROM SAMPLE_TABLE");
foreach($DbControl->data as $items)
{
echo $items['SAMPLE_COLUMN_NAME'];
}
?>
를 호출하려고 내 index.php를 내가 틀린 것 같다 모르겠어요 내 기능
<?php
class DbControl{
public $dbstr ='(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(HOST = XX.XXX.XXX.XX)(PORT = XXXX))
)
(CONNECT_DATA =
(SID = XXXXX)
)
)';
public $user = "XXXXX";
public $password = "XXXXX";
function connect(){
$this->connection = oci_connect($this->user,$this->password,$this->dbstr) or die(oci_error());
}
function execute($query){
$this -> connect(); //Database Connect
$this -> statement = oci_parse($this->connection,$query); //prepare the statement
$this -> execute = oci_execute($this -> statement); //execute the statement
$this -> totalRows = oci_num_rows($this -> statement); //get total number of rows
$this -> data = array();
if($this -> totalRows > 0){
//fetch data
while($result = oci_fetch_array($this->statement)){
$this -> data[] = $result;
}
}
}
}
?>
내 dbcontrol.php입니다 . 하지만 매번 이걸 실행합니다. 페이지에 아무 것도 표시되지 않습니다. 결과 없음, 데이터 없음. 그러나 데이터베이스에 데이터가 있다고 확신합니다.
이 링크가 유용한 것으로 나타났습니다. http://st-curriculum.oracle.com/obe/db/11g/r2/prod/appdev/opensrclang/phphol2010_db/php_db.htm – Microtechie
왜 PDO를 사용하지 않습니까? 그것은 오라클 afaik 포함한 데이터베이스의 모든 종류를 처리 할 수 있습니다 –