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,70 +4,65 @@ 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) {
exit('Error: ' . $exception->getMessage() . " on database: $database<br />");
} }
$this->prefix = $prefix;
mysql_query("SET NAMES 'utf8'", $this->link); $this->affected = 0;
mysql_query("SET CHARACTER SET utf8", $this->link);
} }
public function query($sql) { 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); $i = 0;
$data = array();
if($resource){ $s = $this->link->prepare($sql);
if(is_resource($resource)){ if(!$s) { return $query; }
$i = 0;
$data = array(); $s->execute($arr);
while ($result = mysql_fetch_assoc($resource)) { $this->affected = $s->rowCount();
$data[$i] = $result;
$i++; $R = $s->fetchAll();
}
mysql_free_result($resource); while(list ($k, $v) = each($R)){
$data[$i] = $v;
$query->row = isset($data[0]) ? $data[0] : array(); $i++;
$query->rows = $data;
$query->num_rows = $i;
unset($data);
$time_end = microtime(true);
$query->exec_time = $time_end - $time_start;
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;
} }
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $i;
$query->error = 0;
$query->errmsg = "";
unset($data);
$time_end = microtime(true);
$query->exec_time = $time_end - $time_start;
return $query;
} }
@ -81,10 +76,7 @@ class Sphinx {
} }
public function __destruct() { public function __destruct() { }
mysql_close($this->link);
}
} }