5 function db_escape_string($str) {
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
12 class CLASS_DATABASE extends PDO {
13 //All functions in this class are deprecated!
14 //Please use only native PDO functions!
22 var $_halt_on_error = true;
24 function __construct() {
25 $this->connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
28 protected function connect($host, $user, $password, $database, $halt_on_error = true) {
30 parent::__construct("mysql:host=$host;dbname=$database", $user,
33 $error='chcipla databaza';
34 $this->exception($error); //deprecated
36 $this->setAttribute(PDO::ATTR_STATEMENT_CLASS,
37 array('result', array($this)));
39 $this->_halt_on_error = $halt_on_error;
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);
51 // mysql_query('set character set utf8');
55 $this->_password=$password;
57 if ($this->_linkId == false || mysql_select_db($database, $this->_linkId) == false) {
58 $this->exception("1Database failed.");
62 $this->_database=$database;
68 function update($sql) { //DEPRECATED!!! Use $db->query($sql)->rowCount(); instead!!!
70 $this->_linkId = false;
71 $this->connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
75 $this->_queryId = $this->query($sql);
76 if ($this->_queryId == false) {
77 $this->exception("update failed.");
79 $rows = @$this->_queryId->rowCount();
83 function getLastInsertId() { //DEPRECATED!!! Use $db->lastInsertId(); instead!!!
84 return (@$this->lastInsertId());
87 protected function exception($errorMessage) {
90 //echo @mysql_error($this->_linkId)," (",@mysql_errno($this->_linkId),")";
93 if ($this->_halt_on_error) {
94 die("<pre>".$errorMessage."</pre>");
96 echo $errorMessage."<br>";