-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlConn.php
More file actions
60 lines (52 loc) · 1.24 KB
/
SqlConn.php
File metadata and controls
60 lines (52 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Created by PhpStorm.
* User: 刘远栋
* Date: 2018/1/2
* Time: 10:35
*/
header("Content-Type: text/html; charset=utf-8");
class SqlConn
{
public $conn;
public $user="c##scott";
public $pass="scott";
public $db="";
public $encode='utf8';
public function __construct(){
$this->conn=oci_connect($this->user,$this->pass,$this->db,$this->encode,OCI_DEFAULT);
if(!$this->conn){
die("连接失败".oci_error());
}
}
public function executeSql($sql,$fetch_type=OCI_ASSOC){
$rows=array();
$stmt=oci_parse($this->conn,$sql);
oci_execute($stmt);
while($res=oci_fetch_array($stmt,$fetch_type)){
$rows[]=$res;
}
return $rows;
}
public function executeDml($sql){
$stmt=oci_parse($this->conn,$sql);
if(oci_execute($stmt)){
return 1;
}else{
return 0;
}
}
public function updateDml($sql){
$stmt=oci_parse($this->conn,$sql);
if(oci_execute($stmt)){
return 1;
}else{
return 0;
}
}
public function close_conn(){
if(!empty($this->conn)){
oci_close($this->conn);
}
}
}