345 |
richard |
1 |
<?php
|
|
|
2 |
// $Id$
|
|
|
3 |
function da_sql_limit($limit,$point,$config)
|
|
|
4 |
{
|
|
|
5 |
switch($point){
|
|
|
6 |
case 0:
|
|
|
7 |
return '';
|
|
|
8 |
case 1:
|
|
|
9 |
return "AND ROWNUM <= $limit";
|
|
|
10 |
case 2:
|
|
|
11 |
return '';
|
|
|
12 |
}
|
|
|
13 |
}
|
|
|
14 |
|
|
|
15 |
function da_sql_host_connect($server,$config)
|
|
|
16 |
{
|
|
|
17 |
if ($config[sql_use_http_credentials] == 'yes'){
|
|
|
18 |
global $HTTP_SERVER_VARS;
|
|
|
19 |
$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
|
|
|
20 |
$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
|
|
|
21 |
}
|
|
|
22 |
else{
|
|
|
23 |
$SQL_user = $config[sql_username];
|
|
|
24 |
$SQL_passwd = $config[sql_password];
|
|
|
25 |
}
|
|
|
26 |
$link = @ocilogon($SQL_user, $SQL_passwd, $config[sql_database]);
|
|
|
27 |
$res = @da_sql_query($link,$config,"ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM'");
|
|
|
28 |
return $link;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
function da_sql_connect($config)
|
|
|
32 |
{
|
|
|
33 |
if ($config[sql_use_http_credentials] == 'yes'){
|
|
|
34 |
global $HTTP_SERVER_VARS;
|
|
|
35 |
$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
|
|
|
36 |
$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
|
|
|
37 |
}
|
|
|
38 |
else{
|
|
|
39 |
$SQL_user = $config[sql_username];
|
|
|
40 |
$SQL_passwd = $config[sql_password];
|
|
|
41 |
}
|
|
|
42 |
$link = @ocilogon($SQL_user, $SQL_passwd, $config[sql_database]);
|
|
|
43 |
$res = @da_sql_query($link,$config,"ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM'");
|
|
|
44 |
return $link;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
function da_sql_pconnect($config)
|
|
|
48 |
{
|
|
|
49 |
if ($config[sql_use_http_credentials] == 'yes'){
|
|
|
50 |
global $HTTP_SERVER_VARS;
|
|
|
51 |
$SQL_user = $HTTP_SERVER_VARS["PHP_AUTH_USER"];
|
|
|
52 |
$SQL_passwd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];
|
|
|
53 |
}
|
|
|
54 |
else{
|
|
|
55 |
$SQL_user = $config[sql_username];
|
|
|
56 |
$SQL_passwd = $config[sql_password];
|
|
|
57 |
}
|
|
|
58 |
$link = @ociplogon($SQL_user, $SQL_passwd, $config[sql_database]);
|
|
|
59 |
$res = @da_sql_query($link,$config,"ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF TZH:TZM'");
|
|
|
60 |
return $link;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
function da_sql_close($link,$config)
|
|
|
64 |
{
|
|
|
65 |
@ociclose($link);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
function da_sql_escape_string($string)
|
|
|
69 |
{
|
|
|
70 |
return addslashes($string);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
function da_sql_query($link,$config,$query)
|
|
|
74 |
{
|
|
|
75 |
$trimmed_query = rtrim($query, ";");
|
|
|
76 |
if ($config[sql_debug] == 'true') {
|
|
|
77 |
print "<b>DEBUG(SQL,OCI DRIVER): Query: <i>$trimmed_query</i></b><br>\n";
|
|
|
78 |
}
|
|
|
79 |
$statement = OCIParse($link,$trimmed_query);
|
|
|
80 |
OCIExecute($statement);
|
|
|
81 |
return $statement;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
function da_sql_num_rows($statement,$config)
|
|
|
85 |
{
|
|
|
86 |
// Unfortunately we need to fetch the statement as ocirowcount doesn't work on SELECTs
|
|
|
87 |
$rows = OCIFetchStatement($statement,$res);
|
|
|
88 |
|
|
|
89 |
if ($config[sql_debug] == 'true'){
|
|
|
90 |
print "<b>DEBUG(SQL,OCI DRIVER): Query Result: Num rows:: " . $rows . "</b><br>\n";
|
|
|
91 |
}
|
|
|
92 |
// Unfortunately we need to re-execute because the statement cursor is reset after OCIFetchStatement :-(
|
|
|
93 |
OCIExecute($statement);
|
|
|
94 |
return $rows;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
function da_sql_fetch_array($statement,$config)
|
|
|
99 |
{
|
|
|
100 |
OCIFetchInto($statement, $temprow, OCI_ASSOC);
|
|
|
101 |
$row = array_change_key_case($temprow, CASE_LOWER);
|
|
|
102 |
if ($config[sql_debug] == 'true') {
|
|
|
103 |
print "<b>DEBUG(SQL,OCI DRIVER): Query Result: <pre>";
|
|
|
104 |
print_r($row);
|
|
|
105 |
print "</b></pre>\n";
|
|
|
106 |
}
|
|
|
107 |
return $row;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
function da_sql_affected_rows($link,$statement,$config)
|
|
|
112 |
{
|
|
|
113 |
if ($config[sql_debug] == 'true')
|
|
|
114 |
print "<b>DEBUG(SQL,OCI DRIVER): Query Result: Affected rows:: " . @ocirowcount($statement) . "</b><br>\n";
|
|
|
115 |
return @ocirowcount($statement);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
function da_sql_list_fields($table,$link,$config)
|
|
|
119 |
{
|
|
|
120 |
$res = @da_sql_query($link,$config,"SELECT * from $table WHERE ROWNUM <=1");
|
|
|
121 |
if ($res){
|
|
|
122 |
$fields[res]=Array();
|
|
|
123 |
for ($i = 1;$i<=ocinumcols($res);$i++) {
|
|
|
124 |
array_push($fields[res],strtolower(OCIColumnName($res,$i)));
|
|
|
125 |
}
|
|
|
126 |
$fields[num]=@ocinumcols($res);
|
|
|
127 |
}else{
|
|
|
128 |
return NULL;
|
|
|
129 |
}
|
|
|
130 |
return $fields;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
function da_sql_num_fields($fields,$config)
|
|
|
134 |
{
|
|
|
135 |
return $fields[num];
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
function da_sql_field_name($fields,$num,$config)
|
|
|
139 |
{
|
|
|
140 |
return $fields[res][$num];
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
function da_sql_error($link,$config)
|
|
|
144 |
{
|
|
|
145 |
return ocierror($link);
|
|
|
146 |
}
|
|
|
147 |
?>
|