1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 class DSNHelper {
14 15 16 17 18 19 20
21 public static function cubrid($db, $host = "localhost", $port = "") {
22 $dsn = "cubrid:";
23
24 if ($db) { $dsn .= "dbname=$db;"; }
25 if ($host) { $dsn .= "host=$host;"; }
26 if ($port) { $dsn .= "port=$port;"; }
27
28 return $dsn;
29 }
30
31 32 33 34 35 36 37 38
39 public static function sybase($db, $host = "localhost", $charset = "", $appname = "") {
40 $dsn = "sybase:";
41
42 if ($db) { $dsn .= "dbname=$db;"; }
43 if ($host) { $dsn .= "host=$host;"; }
44 if ($charset) { $dsn .= "charset=$charset;"; }
45 if ($appname) { $dsn .= "appname=$appname;"; }
46
47 return $dsn;
48 }
49
50 51 52 53 54 55 56
57 public static function firebird($db, $charset = "", $role = "") {
58 $dsn = "firebird:";
59
60 if ($db) { $dsn .= "dbname=$db;"; }
61 if ($charset) { $dsn .= "charset=$charset;"; }
62 if ($role) { $dsn .= "role=$role;"; }
63
64 return $dsn;
65 }
66
67 68 69 70 71
72 public static function ibm_ini($ini) {
73 return "ibm:dsn=$ini";
74 }
75
76 77 78 79 80 81 82 83 84
85 public static function ibm($db, $host = "localhost", $port = "", $usr = "", $pwd = "") {
86 $dsn = "ibm:driver={ibm db2 odbc driver};protocol=tcpip;";
87
88 if ($db) { $dsn .= "database=$db;"; }
89 if ($host) { $dsn .= "hostname=$host;"; }
90 if ($port) { $dsn .= "port=$port;"; }
91 if ($usr) { $dsn .= "uid=$usr;"; }
92 if ($pwd) { $dsn .= "pwd=$pwd;"; }
93
94 return $dsn;
95 }
96
97 98 99 100 101
102 public static function informix_ini($ini) {
103 return "informix:dsn=$ini";
104 }
105
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
124 public static function informix($db, $server, $app, $connection_pooling, $encrypt, $failover_partner, $login_timeout, $multiple_active_result_sets, $quoted_id, $trace_file, $trace_on, $transaction_isolation, $trust_server_certificate, $wsid) {
125 $dsn = "sqlsrv:";
126
127 if ($db) { $dsn .= "database=$db;"; }
128 if ($server) { $dsn .= "server=$server;"; }
129 if ($app) { $dsn .= "app=$app;"; }
130 if ($connection_pooling) { $dsn .= "connectionpooling=$connection_pooling;"; }
131 if ($encrypt) { $dsn .= "encrypt=$encrypt;"; }
132 if ($failover_partner) { $dsn .= "failover_partner=$failover_partner;"; }
133 if ($login_timeout) { $dsn .= "logintimeout=$login_timeout;"; }
134 if ($multiple_active_result_sets) { $dsn .= "multipleactiveresultsets=$multiple_active_result_sets;"; }
135 if ($quoted_id) { $dsn .= "quotedid=$quoted_id;"; }
136 if ($trace_file) { $dsn .= "tracefile=$trace_file;"; }
137 if ($trace_on) { $dsn .= "traceon=$trace_on;"; }
138 if ($transaction_isolation) { $dsn .= "transactionisolation=$transaction_isolation;"; }
139 if ($trust_server_certificate) { $dsn .= "trustservercertificate=$trust_server_certificate;"; }
140 if ($wsid) { $dsn .= "wsid=$wsid;"; }
141
142 return $dsn;
143 }
144
145 146 147 148 149 150 151 152
153 public static function mysql($db, $host = "localhost", $port = "", $charset = "") {
154 $dsn = "mysql:";
155
156 if ($db) { $dsn .= "dbname=$db;"; }
157 if ($host) { $dsn .= "host=$host;"; }
158 if ($port) { $dsn .= "port=$port;"; }
159 if ($charset) { $dsn .= "charset=$charset;"; }
160
161 return $dsn;
162 }
163
164 165 166 167 168 169 170
171 public static function mysql_socket($db, $unix_socket, $charset = "") {
172 $dsn = "mysql:";
173
174 if ($db) { $dsn .= "dbname=$db;"; }
175 if ($unix_socket) { $dsn .= "unix_socket=$unix_socket;"; }
176 if ($charset) { $dsn .= "charset=$charset;"; }
177
178 return $dsn;
179 }
180
181 182 183 184 185
186 public static function oci($db) {
187 return "oci:dbname=$db";
188 }
189
190 191 192 193 194
195 public static function odbc($db) {
196 return "odbc:$db";
197 }
198
199 200 201 202 203 204 205 206 207 208
209 public static function odbc_full($db, $host = "localhost", $port = "", $protocol = "", $usr = "", $pwd = "") {
210 $dsn = "odbc:driver={ibm db2 odbc driver};";
211
212 if ($db) { $dsn .= "database=$db;"; }
213 if ($host) { $dsn .= "hostname=$host;"; }
214 if ($port) { $dsn .= "port=$port;"; }
215 if ($protocol) { $dsn .= "protocol=$protocol;"; }
216 if ($usr) { $dsn .= "uid=$usr;"; }
217 if ($pwd) { $dsn .= "pwd=$pwd;"; }
218
219 return $dsn;
220 }
221
222 223 224 225 226 227
228 public static function odbc_msaccess($mdb, $usr) {
229 return "odbc:Driver={Microsoft Access Driver (*.mdb)};dbq=$mdb;uid=$usr";
230 }
231
232 233 234 235 236 237 238 239 240
241 public static function pgsql($db, $host = "localhost", $port = "", $usr = "", $pwd = "") {
242 return "pgsql:";
243
244 if ($db) { $dsn .= "dbname=$db;"; }
245 if ($host) { $dsn .= "host=$host;"; }
246 if ($port) { $dsn .= "port=$port;"; }
247 if ($usr) { $dsn .= "user=$usr;"; }
248 if ($pwd) { $dsn .= "password=$pwd;"; }
249
250 return $dsn;
251 }
252
253 254 255 256 257
258 public static function sqlite($db) {
259 return "sqlite:$db";
260 }
261
262 263 264 265
266 public static function sqlite_in_memory() {
267 return "sqlite::memory:";
268 }
269
270 271 272 273 274
275 public static function sqlite2($db) {
276 return "sqlite2:$db";
277 }
278
279 280 281 282
283 public static function sqlite2_in_memory() {
284 return "sqlite2::memory:";
285 }
286
287 }
288
289 ?>
290