<?phpphp
/**html
* 因为公司的须要,使用php+oracle开发项目,oracle由于有专门人员开发设计,咱们只需远程调用mysql
*因而乎遇到了蛋疼的问题就是开启oracle扩展的问题,虽然你在php.ini文件中打开了extension=php_oci8.dllsql
*单身在phpinfo中仍然看不到oracle扩展,这样oracle的操做方法就不能用,数据库
*因而就要去oracle官方网上下载一个文件包 instantclient-basic-nt-11.2.0.3.0.zip,oracle
*解压到任意地方,而后将D:\instantclient这个地址配置到环境变量里面这样*oracle的扩展就会开启,天然方法均可以使用了,就像用mysql同样了fetch
*固然数据库链接类仍是须要的因而我就写了一个php链接oracle的类以下this
*/spa
class oracle{设计
public $user; //用户
public $pass; //密码
public $dbname;//数据库
public function __construct($user='lms',$pass='lms',$dbname='192.168.2.77ot'){
$this->user=$user;
$this->pass=$pass;
$this->dbname=$dbname;
}
//链接数据库
function conn(){
$link = oci_connect($this->user,$this->pass,$this->dbname);
return $link;
}
public function oracle_fetch_all($sql,$status='1'){
$link = $this->conn();
if(!$status){
echo $sql."<br/>";
}
$stmt = oci_parse($link,$sql);
$r = oci_execute($stmt);
if (!$r ){
$this->oracle_error($stmt);
}
while(!!$row = oci_fetch_array($stmt,OCI_BOTH)){
$data[] = $row;
}
return $data;
}
public function oracle_fetch_row($sql,$status='1'){
$link = $this->conn();
if(!$status){
echo $sql."<br/>";
}
$stid = oci_parse($link, $sql);
$r = oci_execute($stid);
if (!$r){
$this->oracle_error($stid);
}
$data = oci_fetch_assoc($stid);
return $data;
}
public function oracle_query($sql){
$link = $this->conn();
$stmt = oci_parse($link,$sql);
$r = oci_execute($stmt,OCI_DEFAULT);
if (!$r ){
$this->oracle_error($stid);
}
return $r;
}
public function oracle_commit(){
$link = $this->conn();
$committed = oci_commit($link);
return $committed;
}
public function oracle_error($stid){
if (!empty($stid)){
$e = oci_error($stid);
trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
}
public function oracle_rollback(){
$link = $this->conn();
if (!empty($link)){
$r = oci_rollback($link);
}
return $r;
}
}
$oracle = new oracle();
$sql = "SELECT * from T_LMS_USERS where USERID='2'";
$data = $oracle->oracle_fetch_row($sql,0);
print_r ($data);
?>