changed the sphinx driver to pdo::mysql

This commit is contained in:
SJ 2012-08-07 22:20:07 +02:00
parent 80284419d7
commit babd0f31f5

View File

@ -4,49 +4,58 @@ class Sphinx {
private $link; private $link;
private $prefix; private $prefix;
public function __construct($hostname, $username, $password, $database, $prefix = NULL) { public function __construct($hostname, $username, $password, $database, $prefix = NULL) {
if (!$this->link = mysql_connect($hostname, $username, $password)) { list($host, $port) = explode(":", $hostname);
exit('Error: Could not make a database connection using ' . $username . '@' . $hostname);
try {
$this->link = new PDO("mysql:host=$host;port=$port;dbname=$database;charset=utf8", $username, $password);
} }
catch(PDOException $exception) {
$this->prefix = $prefix; exit('Error: ' . $exception->getMessage() . " on database: $database<br />");
mysql_query("SET NAMES 'utf8'", $this->link);
mysql_query("SET CHARACTER SET utf8", $this->link);
} }
public function query($sql) { $this->affected = 0;
}
public function select_db($database) { }
public function query($sql, $arr = array()) {
$query = new stdClass(); $query = new stdClass();
$query->error = 1;
$query->errmsg = "Error";
$query->query = $sql; $query->query = $sql;
$query->error = 0;
$query->errmsg = "";
$time_start = microtime(true); $time_start = microtime(true);
$resource = mysql_query(str_replace('#__', $this->prefix, $sql), $this->link);
if($resource){
if(is_resource($resource)){
$i = 0; $i = 0;
$data = array(); $data = array();
while ($result = mysql_fetch_assoc($resource)) { $s = $this->link->prepare($sql);
$data[$i] = $result; if(!$s) { return $query; }
$s->execute($arr);
$this->affected = $s->rowCount();
$R = $s->fetchAll();
while(list ($k, $v) = each($R)){
$data[$i] = $v;
$i++; $i++;
} }
mysql_free_result($resource);
$query->row = isset($data[0]) ? $data[0] : array(); $query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data; $query->rows = $data;
$query->num_rows = $i; $query->num_rows = $i;
$query->error = 0;
$query->errmsg = "";
unset($data); unset($data);
$time_end = microtime(true); $time_end = microtime(true);
@ -55,20 +64,6 @@ class Sphinx {
return $query; return $query;
} }
else {
return $query;
}
}
else {
$_SESSION['error'] = 'Error: ' . mysql_error() . '<br />Error No: ' . mysql_errno() . '<br />' . $sql;
$query->errmsg = 'Error: ' . mysql_error() . '<br />Error No: ' . mysql_errno() . '<br />' . $sql;
$query->error = 1;
return $query;
}
}
public function countAffected() { public function countAffected() {
@ -81,10 +76,7 @@ class Sphinx {
} }
public function __destruct() { public function __destruct() { }
mysql_close($this->link);
}
} }