diff --git a/delete-comic.php b/delete-comic.php index 0f1bff7..89493f9 100644 --- a/delete-comic.php +++ b/delete-comic.php @@ -9,7 +9,7 @@ check_nonce('delete-strip-'.(int)$_REQUEST['strip_id']); if(!deletestrip( $_REQUEST['strip_id'] )) { - adminlog("Error deleting strip $_REQUEST[strip_id]:".mysqli_error(), MTS_STRIP, MTA_DELETE, E_ERROR); + adminlog("Error deleting strip $_REQUEST[strip_id]:".$dbConnection->errorCode(), MTS_STRIP, MTA_DELETE, E_ERROR); mtdie('Error deleting the specified strip.','SQL Error'); } diff --git a/delete-page.php b/delete-page.php index d535cbf..b3fa09d 100644 --- a/delete-page.php +++ b/delete-page.php @@ -9,7 +9,7 @@ check_nonce('delete-page-'.$_REQUEST['page_name']); if(!deletepage( $_REQUEST['page_name'] )) { - adminlog("Error deleting page $_REQUEST[page_name]: ".mysqli_error(), MTS_PAGE, MTA_DELETE, E_ERROR); + adminlog("Error deleting page $_REQUEST[page_name]: ".$dbConnection->errorCode(), MTS_PAGE, MTA_DELETE, E_ERROR); mtdie('Error deleting the specified page.','SQL Error'); } diff --git a/delete-rant.php b/delete-rant.php index 122d598..e368f05 100644 --- a/delete-rant.php +++ b/delete-rant.php @@ -9,7 +9,7 @@ check_nonce('delete-rant-'.(int)$_REQUEST['rant_id']); if(!deleterant( $_REQUEST['rant_id'] )) { - adminlog("Error deleting rant $_REQUEST[rant_id]: ".mysqli_error(), MTS_RANT, MTA_DELETE, E_ERROR); + adminlog("Error deleting rant $_REQUEST[rant_id]: ".$dbConnection->errorCode(), MTS_RANT, MTA_DELETE, E_ERROR); mtdie('Error deleting the specified rant.','SQL Error'); } diff --git a/edit-comic.php b/edit-comic.php index 28d170b..c6c36f2 100644 --- a/edit-comic.php +++ b/edit-comic.php @@ -53,8 +53,8 @@ if( $_POST ) { // Insert new strip into the database, get a real $strip->id if(!insertstrip( $strip )) { - adminlog("Error on insertion of new strip: ".mysqli_error(), MTS_STRIP, MTA_ADD, E_ERROR); - mtdie('Error on insertion of new strip: '.mysqli_error(), 'SQL Error'); + adminlog("Error on insertion of new strip: ".$dbConnection->errorCode(), MTS_STRIP, MTA_ADD, E_ERROR); + mtdie('Error on insertion of new strip: '.$dbConnection->errorCode(), 'SQL Error'); } // Store the uploaded file to xxxx-0.ext @@ -99,7 +99,7 @@ if( $_POST ) { if(!updatestrip( $strip ) ) { adminlog("Failed to update strip ".$strip->id.".", MTS_STRIP, MTA_UPDATE); - mtdie('Error updating strip: ' . mysqli_error(), 'SQL Error'); + mtdie('Error updating strip: ' . $dbConnection->errorCode(), 'SQL Error'); } if( is_valid_upload('comicFile') ) { // If uploading, store the uploaded file to xxxx-n.ext diff --git a/edit-rant.php b/edit-rant.php index f262891..1608307 100644 --- a/edit-rant.php +++ b/edit-rant.php @@ -62,7 +62,7 @@ if( $_POST ) { $rant->id = insertrant($rant); if( $rant->id === false ) { - adminlog("Error on rant insertion: ".mysqli_error(), MTS_RANT, MTA_INSERT, E_ERROR); + adminlog("Error on rant insertion: ".$dbConnection->errorCode(), MTS_RANT, MTA_INSERT, E_ERROR); mtdie('There was an error inserting the rant into the database.', 'SQL Error'); } diff --git a/fredart_parse.php b/fredart_parse.php index c90c692..011aeee 100644 --- a/fredart_parse.php +++ b/fredart_parse.php @@ -24,12 +24,8 @@ for ($count = 0; $count < 5; $count++) { $entry = $feed->getEntryByOffset($count); - $link = mysqli_real_escape_string($mtdb->link, $entry->link); - $title = mysqli_real_escape_string($mtdb->link, $entry->title); - $date = $entry->pubdate; - $mtdb->query("INSERT INTO fredart (pubdate, title, link) - VALUES (FROM_UNIXTIME($date), '$title', '$link')", false); + $dbConnection->executeUpdate('INSERT INTO fredart (pubdate, title, link) VALUES (FROM_UNIXTIME(?), ?, ?)', array($entry->pubdate, $entry->title, $entry->link)); } header('Content-Type: text/xml'); diff --git a/include/admin.inc.php b/include/admin.inc.php index aa2b6a2..b14ad0d 100644 --- a/include/admin.inc.php +++ b/include/admin.inc.php @@ -6,7 +6,6 @@ require(__DIR__ . '/../vendor/autoload.php'); // Core lib require_once('html.php'); -require_once('mysql.php'); require_once('cookies.php'); require_once('functions.php'); require_once('error.php'); @@ -42,9 +41,6 @@ $dbParams = array( $dbConnection = \Doctrine\DBAL\DriverManager::getConnection($dbParams, $dbConfig); $dbConnection->setFetchMode(PDO::FETCH_OBJ); -$mtdb = new MysqlStore(); -$mtdb->connect( DB_SERVER, DB_WRITE_USER, DB_WRITE_PASS, DB_NAME ); - /* TODO: Move these definitions to LocalSettings.php */ if ( !defined('RANTIMG') ) define('RANTIMG', '../rantimgs/'); diff --git a/include/twitter.php b/include/twitter.php index 6404edf..8774d6c 100644 --- a/include/twitter.php +++ b/include/twitter.php @@ -53,7 +53,7 @@ function twitterpost($message, $user=TWITTER_USER, $password=TWITTER_PASS) function setOAuthTokens($userid,$oauth_token,$oauth_token_secret, $username) { - global $mtdb; + global $dbConnection; $id = (int)$userid; if ($dbConnection->executeUpdate('UPDATE twitter_user SET oauth_token = ?, oauth_token_secret = ?, username = ? WHERE id = ?', array($oauth_token, $oauth_token_secret, $username, $id))) return true; diff --git a/index.php b/index.php index dc40a9a..5b3e96c 100644 --- a/index.php +++ b/index.php @@ -46,7 +46,7 @@ adminmenu();
Deleted type successfully.
'; adminlog("Deleted type ".(int)$_GET['delete'], MTS_TYPE, MTA_DELETE); @@ -27,10 +27,10 @@ if( isset($_POST['action']) && $_POST['action'] == 'new_type' ) { $desc = trim($_POST['description']); if( check_type_name($name) ) { - if(! $mtdb->query( sprintf( 'INSERT INTO strip_t(name, description) VALUES("%s", "%s")', mysqli_real_escape_string($mtdb->link, $name), mysqli_real_escape_string($mtdb->link, $desc)) ) ) + if(! $dbConnection->executeUpdate('INSERT INTO strip_t (name, description) VALUES (?, ?)', array($name, $desc))) { adminlog("Error on insertion of new type.", MTS_TYPE, MTA_INSERT, E_WARNING); - mtdie("Error on insertion of new type: ". htmlentities(mysqli_error()), 'SQL Error'); + mtdie("Error on insertion of new type: ". $dbConnection->errorCode(), 'SQL Error'); } } $info.='
New type created successfully.
'; @@ -47,7 +47,7 @@ if( isset($_POST['action']) && $_POST['action'] == 'edit_type' ) { $meta = $_POST['meta']; - $m_delete = $mtdb->getAll("SELECT meta FROM meta WHERE type = $id"); + $m_delete = $dbConnection->fetchAll('SELECT meta FROM meta WHERE type = ?', array($id)); $m_insert = array(); @@ -67,31 +67,31 @@ if( isset($_POST['action']) && $_POST['action'] == 'edit_type' ) { } if( check_type_name( $name ) ) { - if( !$mtdb->query( sprintf( 'UPDATE strip_t SET name = "%s", description = "%s" WHERE id = %s', mysqli_real_escape_string($mtdb->link, $name), mysqli_real_escape_string($mtdb->link, $desc), $id)) ) + if( !$dbConnection->executeUpdate('UPDATE strip_t SET name = ?, description = ? WHERE id = ?', array($name, $desc, $id))) { adminlog("Error on updating type ".$id, MTS_TYPE, MTA_UPDATE, E_WARNING); - mtdie("Error on update of existing type: ". htmlentities(mysqli_error()), 'SQL Error'); + mtdie("Error on update of existing type: ". $dbConnection->errorCode(), 'SQL Error'); } $sql_insert = "INSERT INTO meta (type,meta) VALUES " . implode(',',$m_insert); $sql_delete = "DELETE FROM meta WHERE type=$id AND ( " . implode(' OR ',$m_delete) . ' )'; - $mtdb->query('START TRANSACTION'); + $dbConnection->beginTransaction(); if( count($m_insert) ) - if(! $mtdb->query( $sql_insert ) ) + if(! $dbConnection->executeUpdate( $sql_insert ) ) { adminlog("Error inserting new metatype association data for type ".$id, MTS_TYPE, MTA_INSERT, E_WARNING); mtdie("There was an error inserting new metatype association data. Transaction aborted. $sql_insert"); } if( count($m_delete) ) - if(! $mtdb->query( $sql_delete ) ) + if(! $dbConnection->executeUpdate( $sql_delete ) ) { adminlog("Error deleting old metatype association data for type ".$id, MTS_TYPE, MTA_REMOVE, E_WARNING); mtdie("There was an error deleting old metatype data. Transaction aborted. $sql_delete"); } - $mtdb->query('COMMIT'); + $dbConnection->commit(); } else { $error.='
Invalid type name!
'; @@ -101,7 +101,7 @@ if( isset($_POST['action']) && $_POST['action'] == 'edit_type' ) { } //display all types -$types = $mtdb->getAll("SELECT strip_t.id AS id, strip_t.name AS name, strip_t.description AS description, COUNT(strip.id) AS strips FROM strip_t LEFT JOIN strip ON strip.type = strip_t.id GROUP BY strip_t.id"); +$types = $dbConnection->fetchAll('SELECT strip_t.id AS id, strip_t.name AS name, strip_t.description AS description, COUNT(strip.id) AS strips FROM strip_t JOIN strip ON strip.type = strip_t.id GROUP BY strip_t.id'); adminhead('Types'); adminmenu(); @@ -130,9 +130,9 @@ adminmenu(); foreach( $types as $s ) { $alternate=!$alternate; - $metas = $mtdb->getAll("SELECT meta_t.name AS name FROM strip_t + $metas = $dbConnection->fetchAll('SELECT meta_t.name AS name FROM strip_t JOIN meta ON meta.type = strip_t.id JOIN meta_t ON meta.meta = meta_t.id - WHERE strip_t.id = $s->id"); + WHERE strip_t.id = ?', array($s->id)); $meta = implode(', ', array_map('_getMetaNameFromObject', $metas) );