*Hello**
This has been a question for a long time / Request for help for a PHP script.
A year ago I created a homepage for a friend (online tutoring website) and installed a finished script for an occupancy calendar and did not consider / knew that the server will soon be switching to PHP 7.2. I could already test and adjust the rest of the homepage, but unfortunately I am with my Latin at the end and of course the calendar does not work.
The problem is of course the database connection .... mysq under PHP 7.2, which I get not fixed
My question:
Can someone take a look at the code and tell them to adapt and / or have tips for me? I would like to understand where the dog is buried and change it myself, but without help, I'm just not coming.
Furthermore, the whole covers about 19 pages and if I post all here, it's probably confusing. I would send the package by email if I get help.
<?php
// Kalender Version
define ('VERSION', '2.1.4');
// PHP version
$php_version_required = '5.0.0';
$php_version_current = phpversion ();
if (version_compare ($php_version_current, $php_version_required, '<')) {
die ('ERROR: PHP version ' . $php_version_required . ' or later required! You have installed ' . $php_version_current . '.');
}
// Session
session_start ();
// Includes
require_once BASEDIR . 'includes/db.class.php';
require_once BASEDIR . 'includes/cal.class.php';
require_once BASEDIR . 'includes/functions.inc.php';
require_once BASEDIR . 'includes/config.inc.php';
// Variables
$r = ''; // Output buffer
$pageTitle = '';
$lang = '';
$langFromUser = false;
// PHP runtime settings
if (DEBUG) {
ini_set ('display_errors', 1);
error_reporting (E_ALL);
}
else {
ini_set ('display_errors', 0);
}
// Language part 1: before db connection
// If language is stored in GET or SESSION, use this
if (isset ($_GET['lang']))
$lang = $_GET['lang'];
elseif (isset ($_SESSION['lang']))
$lang = $_SESSION['lang'];
// Validate or use de as default
$lang = preg_replace ('/[^a-z_]*/', '', $lang);
$langFile = BASEDIR . 'lang/' . $lang . '.inc.php';
if (file_exists ($langFile))
$langFromUser = true;
else {
$lang = 'de';
$langFile = BASEDIR . 'lang/' . $lang . '.inc.php';
}
if (file_exists ($langFile)) {
require_once $langFile; // Include
$_SESSION['lang'] = $lang; // Store in SESSION
}
else
trigger_error ('Language file "' . $langFile . '" not found.', E_USER_ERROR);
// Connect to db and check for errors
$db = new DatabaseConnection ($mysql);
if ($db -> error) {
$pageTitle = __('error');
switch ($db -> error) {
case 1:
$r .= echoError (__('errorDBAuth'));
break;
case 2:
$r .= echoError (__('errorDBSetupNoDB'));
break;
case 3:
$r .= echoError (__('errorDBSetupNoTables'));
break;
case 4:
case 5:
$r .= echoError (__('errorDBSetupVersionsDiffer'));
}
}
// Jobs to do if successfull connected
else {
// Read preferences
$prefs = readPrefs ($db);
// Language part 2: use default language from db, if hard-coded default chosen in part 1
if (!$langFromUser) {
$result = $db -> select ("SELECT `abbr` FROM `languages` WHERE `id`=" . $prefs['languageDefault']);
$langFile = BASEDIR . 'lang/' . $result[0]['abbr'] . '.inc.php';
if (file_exists ($langFile)) {
$lang = $result[0]['abbr'];
require_once $langFile; // Include
$_SESSION['lang'] = $lang; // Store in SESSION
}
}
// Get language id
$result = $db -> select ("SELECT `id` FROM `languages` WHERE `abbr`='" . $lang . "'");
define ('LANG_ID', $result[0]['id']);
// Get active languages
$GLOBALS['langsActive'] = readLanguages ();
}
// Define Language
define ('LANG_ABBR', $lang);
that the "i" is not enough, is clear and I could also apply to the rest of the HP I've made myself.
the 34 pages or * .php files are the whole construct of this occupancy calendar incl. admin area and first installation tool (which is really needed for website)
not every * .php also contains database-relevant scripts
but attached a few snippets of code to see had approximately running
public $error = false;
public $version = false;
private $link = false;
private $config = array ();
/**
* Wrapper for connect ()
* @param $db Array with vars from config
* @return result from connect ()
*/
public function databaseConnection ($mysql) {
$this -> config = $mysql;
return $this -> connect ();
}
/**
* Tries to connect to db and checks installation.
* @return true if no error, else false
*/
public function connect () {
// Reset $error
$this -> error = false;
// Try to connect to db
$this -> link = @mysql_connect ($this -> config['host'] . ':' . $this -> config['port'], $this -> config['user'], $this -> config['pass']);
if (!$this -> link)
$this -> error = 1; // Connection failed.
else {
if (function_exists ('mysql_set_charset'))
mysql_set_charset ('utf8', $this -> link);
// Try to select db
if (mysql_select_db ($this -> config['name'], $this -> link)) {
// Look for prefs table
$version = $this -> select ("SELECT `value` FROM `prefs` WHERE `name`='dbVersion'");
if (!$version) {
// Check for v1.x installation with this year's table
$tables = $this -> select ("SHOW TABLES");
if ($tables) {
foreach ($tables as $table) {
if (in_array ($this -> config['pfix'] . date ('Y'), $table)) {
$this -> error = 5; // v1.x installation found
break;
}
}
}
if (!$this -> error)
$this -> error = 3; // Table does not exist
}
// Check for db version
else {
$this -> version = $version[0]['value'];
if ($this -> version != VERSION)
$this -> error = 4; // DB-Version and Files-Version differ
}
}
else
$this -> error = 2; // Database does not exist
}
if ($this -> error)
return false;
else
return true;
}`