Use PDO instead of MySQLi

This commit is contained in:
Ruan 2015-06-06 08:56:33 +02:00
parent 1041830c20
commit c18750007d
5 changed files with 12 additions and 14 deletions

View File

@ -36,7 +36,7 @@
<?php
global $table_bans, $conn;
$result = run_query($table_bans);
while ($row = $result->fetch_assoc()) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
date_default_timezone_set("UTC");
$timeResult = date('F j, Y, g:i a', $row['time'] / 1000);
$expiresResult = date('F j, Y, g:i a', $row['until'] / 1000);
@ -58,8 +58,6 @@
</td>
</tr>
<?php }
$result->free();
$conn->close();
?>
</tbody>
</table>

View File

@ -13,8 +13,10 @@ function get_query($table) {
function run_query($table) {
global $conn;
if (!$result = $conn->query(get_query($table))) {
die('Query error: "' . $conn->error . '"');
try {
$result = $conn->query(get_query($table));
} catch (PDOException $ex) {
die($ex->getMessage());
}
return $result;
}

View File

@ -32,10 +32,12 @@ function litebans_connect() {
global $conn, $active_query;
global $table_bans, $table_mutes, $table_warnings, $table_history;
$conn = new mysqli($dbhost, $username, $password, $database);
$dsn = 'mysql:dbname=' . $database . ';host=' . $dbhost . ';charset=utf8';
if ($conn->connect_errno > 0) {
die('Unable to connect to database: ' . $conn->connect_error);
try {
$conn = new PDO($dsn, $username, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$table_bans = $table_prefix . "bans";

View File

@ -26,7 +26,7 @@
<?php
global $table_mutes, $conn;
$result = run_query($table_mutes);
while ($row = $result->fetch_assoc()) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
date_default_timezone_set("UTC");
$timeResult = date('F j, Y, g:i a', $row['time'] / 1000);
$expiresResult = date('F j, Y, g:i a', $row['until'] / 1000);
@ -48,8 +48,6 @@
</td>
</tr>
<?php }
$result->free();
$conn->close();
?>
</tbody>
</table>

View File

@ -33,7 +33,7 @@
<?php
global $table_warnings, $conn;
$result = run_query($table_warnings);
while ($row = $result->fetch_assoc()) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
date_default_timezone_set("UTC");
$expiresResult = date('F j, Y, g:i a', $row['until'] / 1000);
?>
@ -53,8 +53,6 @@
</td>
</tr>
<?php }
$result->free();
$conn->close();
?>
</tbody>
</table>