/sql/sybase
[return to app]1
<?php
2 /**
3 * Converts the procedural Sybase PHP class to object-oriented
4 */
5 class sybase {
6 /**
7 * Database resource ID
8 * @var object
9 */
10 public $resource;
11
12 /**
13 * The database method used to sanitize user input strings
14 */
15 const ESCAPE_STRING = 'escapeString';
16
17 /**
18 * Creates a string sanitation method as it is missing in the Sybase PHP extension
19 *
20 * @param string $var
21 * @return string
22 */
23 public function escapeString($var) {
24 return str_replace("'", "\\'", $var);
25 }
26
27 /**
28 * Connect to Sybase
29 *
30 * @param string $host
31 * @param string $username
32 * @param string $passwd
33 * @param string $dbname Optional
34 * @param boolean $persistent Optional default is true
35 * @param string $charset Optional
36 * @param string $appname Optional
37 * @param boolean $new Optional
38 */
39 public function __construct($host, $username, $password, $dbname = null, $persistent = true,
40 $charset = null, $appname = null, $new = null) {
41 try {
42 $connect = 'sybase_' . ($persistent ? 'pconnect' : 'connect');
43 $this->resource = $connect($host, $username, $password, $charset, $appname, $new);
44 if (!$this->resource) {
45 throw new Exception('Cannot connect to Sybase');
46 }
47 } catch (Exception $e) {
48 $this->error = $e->getMessage();
49 }
50 if ($dbname) {
51 sybase_select_db($dbname, $this->resource);
52 }
53 }
54
55 /**
56 * Catch-all method allowing you to call any Sybase function via camel-cap object-oriented syntax.
57 *
58 * From your models you could access:
59 *
60 * $this->db->fetchAssoc()
61 * $this->db->result()
62 * $this->db->unbufferredQuery()
63 * $this->db->close()
64 * etc.
65 *
66 * @param string $name
67 * @param mixed $val
68 */
69 public function __call($name, $val) {
70 $name = strtolower('sybase_' . preg_replace('/[A-Z]/', '_$0', $name));
71 if (function_exists($name)) {
72 return call_user_func_array($name, $val);
73 }
74 }
75 }