From 4265af93380ec731473341d3f6bf3dbaa0f496d3 Mon Sep 17 00:00:00 2001 From: Jeena Date: Tue, 16 Jun 2020 18:51:51 +0200 Subject: [PATCH] Upgrade to be able to run on PHp7 --- application/controller/PageController.php | 4 +- application/model/Page.php | 4 +- library/Katharsis/Db5.php | 42 +++++++++---------- .../Local/Controller/Plugin/IndexRedirect.php | 2 +- public/index.php | 5 ++- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/application/controller/PageController.php b/application/controller/PageController.php index 5aadcd5..915d3f2 100644 --- a/application/controller/PageController.php +++ b/application/controller/PageController.php @@ -17,7 +17,7 @@ class PageController extends Katharsis_Controller_Abstract } $url = substr($method, 0, -6); // remove Action from urlAction - + $pageId = $this->_page->getIdByUrl($url, $preview); if(!$pageId) { @@ -37,4 +37,4 @@ class PageController extends Katharsis_Controller_Abstract echo $this->_view->render('main'); die(); } -} \ No newline at end of file +} diff --git a/application/model/Page.php b/application/model/Page.php index 4aa375d..164bb9e 100644 --- a/application/model/Page.php +++ b/application/model/Page.php @@ -14,7 +14,7 @@ class Page extends Katharsis_Model_Abstract } $sql = $this->_con->createStatement("SELECT id FROM page WHERE url = :url " . $activeTerm, array("url" => $url)); - + if($result = $this->_con->fetchOne($sql)){ return $result['id']; } @@ -83,4 +83,4 @@ class Page extends Katharsis_Model_Abstract $this->_con->run($sql); } } -?> \ No newline at end of file +?> diff --git a/library/Katharsis/Db5.php b/library/Katharsis/Db5.php index 5469b1b..3bd1c1b 100644 --- a/library/Katharsis/Db5.php +++ b/library/Katharsis/Db5.php @@ -119,7 +119,7 @@ class Katharsis_Db5 public function setDatabase($value) { $this->_database = $value; - $this->_selectDatabase(); + // $this->_selectDatabase(); } /** @@ -174,11 +174,11 @@ class Katharsis_Db5 */ public function connect() { - $this->_connection = mysql_connect( + $this->_connection = mysqli_connect( $this->getHost(), $this->getUser(), $this->getPassword(), - true + $this->getDatabase() ); if(!$this->_connection) @@ -186,7 +186,7 @@ class Katharsis_Db5 throw new KatharsisDb5_Exception('Could not connect to "' . $this->getHost() . '" with user "' . $this->getUser() . '".'); } - $this->_selectDatabase(); + // $this->_selectDatabase(); } /** @@ -196,7 +196,7 @@ class Katharsis_Db5 public function disconnect() { $this->_connection = null; - return (bool) mysql_close($this->_connection); + return (bool) mysqli_close($this->_connection); } /** @@ -269,7 +269,7 @@ class Katharsis_Db5 { if(is_string($value)) { - $value = "'" . mysql_real_escape_string($value, $this->_connection) . "'"; + $value = "'" . mysqli_real_escape_string($value, $this->_connection) . "'"; } if($value === null) { @@ -307,7 +307,7 @@ class Katharsis_Db5 public function count ($statement) { $result = $this->_execute($statement); - $this->_lastRowCount = mysql_num_rows($result); + $this->_lastRowCount = mysqli_num_rows($result); return $this->_lastRowCount; } @@ -426,10 +426,10 @@ class Katharsis_Db5 if($this->_connection !== null) { - $value = mysql_real_escape_string($value); + $value = mysqli_real_escape_string($this->_connection, $value); } else { - $value = mysql_escape_string($value); + $value = mysqli_escape_string($this->_connection, $value); } // if string, or a integer, but wanting to request via LIKE @@ -464,7 +464,7 @@ class Katharsis_Db5 */ public function lastInsertId () { - return mysql_insert_id($this->_connection); + return mysqli_insert_id($this->_connection); } /** @@ -487,7 +487,7 @@ class Katharsis_Db5 { if($this->isConnected() && $this->getDatabase() !== null) { - if(!mysql_select_db($this->getDatabase(), $this->_connection)) + if(!mysqli_select_db($this->getDatabase(), $this->_connection)) { throw new KatharsisDb5_Exception('Could not select database "' . $this->getDatabase() . '".'); } @@ -506,16 +506,16 @@ class Katharsis_Db5 { throw new KatharsisDb5_Exception("Not connected to database."); } - if($result = mysql_query($statement, $this->_connection)) + if($result = mysqli_query($this->_connection, $statement)) { - $this->_lastRowCount = mysql_affected_rows($this->_connection); + $this->_lastRowCount = mysqli_affected_rows($this->_connection); } $this->_lastStatement = $statement; - if(mysql_error($this->_connection)) + if(mysqli_error($this->_connection)) { - $this->_lastError['number'] = mysql_errno($this->_connection); - $this->_lastError['message'] = mysql_error($this->_connection); + $this->_lastError['number'] = mysqli_errno($this->_connection); + $this->_lastError['message'] = mysqli_error($this->_connection); $this->analyseLast(); } else { @@ -549,7 +549,7 @@ class Katharsis_Db5 switch($fetchmode) { case self::FETCHMODE_ASSOC: - while($row = mysql_fetch_assoc($result)) + while($row = mysqli_fetch_assoc($result)) { if($fetchOne) { @@ -563,7 +563,7 @@ class Katharsis_Db5 break; case self::FETCHMODE_ARRAY: - while($row = mysql_fetch_row($result)) + while($row = mysqli_fetch_row($result)) { if($fetchOne) { @@ -614,11 +614,11 @@ class KatharsisDb5_ResultSet switch ($fetchmode) { case Katharsis_Db5::FETCHMODE_ASSOC: - return mysql_fetch_assoc($this->_resultSet); + return mysqli_fetch_assoc($this->_resultSet); break; case Katharsis_Db5::FETCHMODE_ARRAY: - return mysql_fetch_row($this->_resultSet); + return mysqli_fetch_row($this->_resultSet); break; default: @@ -628,4 +628,4 @@ class KatharsisDb5_ResultSet } } -?> \ No newline at end of file +?> diff --git a/library/Local/Controller/Plugin/IndexRedirect.php b/library/Local/Controller/Plugin/IndexRedirect.php index 5b6fcc3..34ee250 100644 --- a/library/Local/Controller/Plugin/IndexRedirect.php +++ b/library/Local/Controller/Plugin/IndexRedirect.php @@ -9,4 +9,4 @@ class Local_Controller_Plugin_IndexRedirect extends Katharsis_Controller_Plugin_ Katharsis_Request::setActionName('home'); } } -} \ No newline at end of file +} diff --git a/public/index.php b/public/index.php index fb2c58c..c4ce697 100644 --- a/public/index.php +++ b/public/index.php @@ -13,11 +13,11 @@ require_once('library/Katharsis/Bootstrap.php'); Katharsis_Autoload::init(); Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Defaults()); +Katharsis_Controller_Plugin::registerPlugin(new Local_Controller_Plugin_IndexRedirect()); Katharsis_Controller_Plugin::registerPlugin(new Local_Controller_Plugin_PageRewrite()); Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_SetNames()); Katharsis_Controller_Plugin::registerPlugin(new Katharsis_Controller_Plugin_StartSession()); Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Notice()); -Katharsis_Controller_Plugin::registerPlugin(new Local_Controller_Plugin_IndexRedirect()); Katharsis_Controller_Plugin::registerPlugin(new Katharsis_Controller_Plugin_Autorender()); Katharsis_Controller_Plugin::registerPlugin(new DidgeridooArtwork_Controller_Plugin_Access()); @@ -28,8 +28,9 @@ try { Katharsis_Bootstrap::run(); } catch(Exception $e) { + http_response_code(500); echo '

Exception thrown

'; echo '

' . $e->getMessage() . '

'; echo '
';
 	print_r($e);
-}
\ No newline at end of file
+}