Commit | Line | Data |
---|---|---|
51ff3226 | 1 | <?php |
51ff3226 | 2 | |
78f1a5f4 | 3 | require("result.inc"); |
51ff3226 | 4 | |
78f1a5f4 H |
5 | function db_escape_string($str) { |
6 | global $db; | |
7 | //This function should be used in whole project instead of *_escape_string() functions! | |
8 | //return mysql_escape_string($str); //XXX TODO $db->quote($str), mysql_real_escape_string() or pg_escape_string() should be used here! | |
9 | return preg_replace('(^.|.$)', '', $db->quote($str)); //XXX HACK | |
51ff3226 | 10 | } |
11 | ||
78f1a5f4 H |
12 | class CLASS_DATABASE extends PDO { |
13 | //All functions in this class are deprecated! | |
14 | //Please use only native PDO functions! | |
51ff3226 | 15 | |
78f1a5f4 H |
16 | var $Master = true; |
17 | var $_linkId = false; | |
18 | var $_url = ""; | |
19 | var $_user = ""; | |
20 | var $_password = ""; | |
21 | var $_database = ""; | |
22 | var $_halt_on_error = true; | |
51ff3226 | 23 | |
78f1a5f4 H |
24 | function __construct() { |
25 | $this->connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); | |
704b65a2 | 26 | } |
51ff3226 | 27 | |
78f1a5f4 H |
28 | protected function connect($host, $user, $password, $database, $halt_on_error = true) { |
29 | global $error; | |
30 | parent::__construct("mysql:host=$host;dbname=$database", $user, | |
31 | $password); | |
32 | /*{ | |
33 | $error='chcipla databaza'; | |
34 | $this->exception($error); //deprecated | |
35 | }; */ | |
36 | $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, | |
37 | array('result', array($this))); | |
51ff3226 | 38 | |
78f1a5f4 H |
39 | $this->_halt_on_error = $halt_on_error; |
40 | $this->_url = $host; | |
41 | $this->_user = $user; | |
42 | $this->_password = $password; | |
43 | /* if ($this->_linkId == false) { | |
44 | $this->_linkId=mysql_connect($host, $user, $password); | |
45 | if ($this->_linkId == false) { | |
46 | $error='chcipla databaza'; | |
47 | $this->exception($error); | |
48 | return false; | |
49 | //die(); | |
50 | }// else { | |
51 | // mysql_query('set character set utf8'); | |
52 | //} | |
53 | $this->_url=$host; | |
54 | $this->_user=$user; | |
55 | $this->_password=$password; | |
56 | ||
57 | if ($this->_linkId == false || mysql_select_db($database, $this->_linkId) == false) { | |
58 | $this->exception("1Database failed."); | |
59 | return false; | |
60 | die(); | |
61 | } | |
62 | $this->_database=$database; | |
63 | } | |
64 | */ | |
65 | return true; | |
51ff3226 | 66 | } |
67 | ||
78f1a5f4 H |
68 | function update($sql) { //DEPRECATED!!! Use $db->query($sql)->rowCount(); instead!!! |
69 | if (!$this->Master) { | |
70 | $this->_linkId = false; | |
71 | $this->connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE); | |
72 | $this->Master = true; | |
51ff3226 | 73 | } |
51ff3226 | 74 | |
78f1a5f4 | 75 | $this->_queryId = $this->query($sql); |
51ff3226 | 76 | if ($this->_queryId == false) { |
77 | $this->exception("update failed."); | |
78 | } | |
78f1a5f4 H |
79 | $rows = @$this->_queryId->rowCount(); |
80 | return ($rows); | |
81 | } | |
51ff3226 | 82 | |
78f1a5f4 H |
83 | function getLastInsertId() { //DEPRECATED!!! Use $db->lastInsertId(); instead!!! |
84 | return (@$this->lastInsertId()); | |
85 | } | |
51ff3226 | 86 | |
78f1a5f4 | 87 | protected function exception($errorMessage) { |
51ff3226 | 88 | |
78f1a5f4 H |
89 | echo "<!-- "; |
90 | //echo @mysql_error($this->_linkId)," (",@mysql_errno($this->_linkId),")"; | |
91 | echo "-->"; | |
51ff3226 | 92 | |
78f1a5f4 H |
93 | if ($this->_halt_on_error) { |
94 | die("<pre>".$errorMessage."</pre>"); | |
51ff3226 | 95 | } else { |
96 | echo $errorMessage."<br>"; | |
97 | return false; | |
98 | } | |
99 | } | |
100 | } | |
78f1a5f4 | 101 |