<?php
class DbConnectionMysql extends DbConnection {
public function connect($host, $login, $pass, $database) {
if($this->link) $this->closeConnection();
$this->link = @mysql_connect($host, $login, $pass);
if(!$this->link) throw new ConnectionException('Could not connect: ' . @mysql_error($this->link));
$success = @mysql_select_db($database, $this->link);
if(!$success)
throw new ConnectionException('Could not select database: '.$database);
}
public function cloneConnection() {
$cloned = new DbConnectionMysql();
$cloned->link = $this->getLink();
return $cloned;
}
public function query($q) {
if(!$this->link)
throw new ConnectionException('No connected to database');
if($q == null)
throw new QueryException('Query string is null');
$this->result = @mysql_query($q, $this->link);
if(!$this->result)
throw new QueryException('Query failed: '.$q.' Error: 'hide@address.com($this->link) . ' Sql: '. $q);
if($this->result === true)
$this->numRows = @mysql_affected_rows($this->link);
else
$this->numRows = @mysql_num_rows($this->result);
return $this->numRows;
}
public function next() {
return @mysql_fetch_array($this->result, MYSQL_ASSOC);
}
public function getLastId() {
return @mysql_insert_id($this->link);
}
public function closeConnection() {
@mysql_close($this->link);
$this->link = null;
}
public function escape($string, $quoted = true) {
if(get_magic_quotes_gpc())
$string=stripslashes($string);
$string = @mysql_real_escape_string($string, $this->link);
$string = $quoted ? '"' . $string . '"' : $string;
return $string;
}
public function startTransaction() {
$this->query('START TRANSACTION');
}
public function commit() {
$this->query('COMMIT');
}
public function rollBack() {
$this->query('ROLLBACK');
}
}
?>