Open skrchnavy opened 8 years ago
Yep, we are running php7, just need to change the DB class to use mysqli or something like that.
I think that is the only major issue
Managed to get it working in version 7,
Maybe still some issues. This is the databaseconnection.php file. That needs updating.
Although, If your installing new, I would recommend you install in version 5 (because of the eval functions and direct calls to the db in the install process) then move to version 7.
<?php /**
/**
@subpackage Library */ class DatabaseConnection { static private $_instance; private $_connection = null; private $_queryResult = null; private $_timeZone; private $_dateDMY; private $_inTransaction;
/**
// FIXME: Remove Session tight-coupling here. if (isset($_SESSION['CATS']) && $_SESSION['CATS']->isLoggedIn()) { self::$_instance->_timeZone = $_SESSION['CATS']->getTimeZoneOffset(); self::$_instance->_dateDMY = $_SESSION['CATS']->isDateDMY(); } else { self::$_instance->_timeZone = OFFSET_GMT * -1; self::$_instance->_dateDMY = false; }
return self::$_instance; }
/* Prevent this class from being instantiated by any means other
public function setInTransaction($tf) { return ($this->_inTransaction = $tf); }
/**
/**
die(
'<!-- NOSPACEFILTER --><p style="background: #ec3737; padding:'
. ' 4px; margin-top: 0; font: normal normal bold 12px/130% '
. 'Arial, Tahoma, sans-serif;">Error Connecting '
. "to Database</p><pre>\n\n" . $error . "</pre>\n\n"
);
return false;
} mysqli_set_charset(SQL_CHARACTER_SET, $this->_connection); $isDBSelected = @mysqli_select_db($this->_connection,DATABASE_NAME); if (!$isDBSelected) { $error = mysqli_error($this->_connection);
die(
'<!-- NOSPACEFILTER --><p style="background: #ec3737; '
. 'padding: 4px; margin-top: 0; font: normal normal bold '
. '12px/130% Arial, Tahoma, sans-serif;">Error Selecting '
. "Database</p><pre>\n\n" . $error . "</pre>\n\n"
);
return false;
}
return true; }
/**
other failure.
/ public function query($query, $ignoreErrors = false) { / Does our current configuration allow the execution of this query? */ if (!$this->allowQuery($query)) { return false; }
/* Fix formatted dates and time zones for localization. */ // FIXME: I don't like rewriting queries.... $query = $this->_localizationFilter($query);
/* Don't limit the execution time of queries. */ set_time_limit(0); $this->_queryResult = mysqli_query($this->_connection,$query);
if (!$this->_queryResult && !$ignoreErrors) { $error = mysqli_error($this->_connection);
echo (
'<!-- NOSPACEFILTER --><p style="background: #ec3737; padding:'
. ' 4px; margin-top: 0; font: normal normal bold 12px/130%'
. ' Arial, Tahoma, sans-serif;">Query Error -- Report to System'
. " Administrator ASAP</p><pre>\n\nMySQL Query Failed: "
. $error . "\n\n" . $query . "</pre>\n\n"
);
echo('<!--');
trigger_error(
str_replace("\n", " ", 'MySQL Query Error: ' . $error . " - " . $query)
);
echo('-->');
die();
}
return $this->_queryResult;
}
/**
foreach ($SQLStatments as $SQL) { $SQL = trim($SQL);
if (empty($SQL))
{
continue;
}
$this->query($SQL);
} }
/**
$numRows = mysqli_num_rows($this->_queryResult); if ($numRows === false) { return false; } else if ($row >= $numRows) { return false; } else if ($row < 0) { return false; }
return $this->mysqli_result($this->_queryResult, $row, $column); }
public function mysqli_result($res,$row=0,$col=0){ $numrows = mysqli_num_rows($res); if ($numrows && $row <= ($numrows-1) && $row >=0){ mysqli_data_seek($res,$row); $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res); if (isset($resrow[$col])){ return $resrow[$col]; } } return false; }
/**
were returned.
*/ public function getAssoc($query = null) { if ($query != null) { $this->query($query); }
$recordSet = mysqli_fetch_assoc($this->_queryResult);
if (empty($recordSet)) { $recordSet = array(); }
return $recordSet; }
/**
if no records were returned.
*/ public function getAllAssoc($query = null) { if ($query != null) { $this->query($query); }
/* Make sure we always return an array. */ $recordSetArray = array();
/* Store all rows in $recordSetArray; */ while (($recordSet = mysqli_fetch_assoc($this->_queryResult))) { $recordSetArray[] = $recordSet; }
/* Return the multi-dimensional record set array. */ return $recordSetArray; }
/**
return mysqli_num_rows($this->_queryResult); }
/**
return false; }
/**
/**
if ($rs['isFreeLock'] == 1) { return true; }
return false; }
/**
/**
/**
/**
for an empty string.
*/ public function makeQueryStringOrNULL($string) { $string = trim($string);
if (empty($string)) { return 'NULL'; }
return $this->makeQueryString($string); }
/**
return (integer) $value; }
/**
/**
if (empty($value) || !preg_match('/^-?[0-9]+(?:.[0-9]+)?$/', $value)) { return '0.0'; }
if ($precision !== false) { $valueAsDouble = round($value, $precision); $isAWholeNumber = fmod($valueAsDouble, 1) == 0; return number_format($valueAsDouble, $isAWholeNumber ? 0 : 2); }
return (string) $value; }
/**
/**
/**
/**
/**
return true; }
// FIXME: Document me. private function _localizationFilter($query) { /* Fix query to allow time results to be offset by $_timeZone. */ if (strpos($query , 'SELECT') !== 0) { return $query; }
// FIXME: This could probably be done better with regexes.
// FIXME: D M Y support.
// FIXME: Document this. Any string-manipulation things like this can
// get fairly confusing if not documented.
$newQuery = '';
while ($query != '')
{
/* Does the query contain a DATE_FORMAT()? */
$dateFormatPosition = strpos($query, 'DATE_FORMAT(');
if ($dateFormatPosition === false)
{
$newQuery .= $query;
$query = '';
continue;
}
if ($dateFormatPosition > 0)
{
$newQuery .= substr($query, 0, strpos($query, 'DATE_FORMAT('));
$query = substr($query, strpos($query, 'DATE_FORMAT('));
}
$working = substr($query, 0, strpos($query, ','));
$query = substr($query, strpos($query, ','));
if (strpos(substr($working, 13), '(') === false)
{
/* Add or subtract time before the date format depeidng on the
* time zone offset. We don't have to do any replacement if the
* offset is 0.
*/
if ($this->_timeZone > 0)
{
$working = str_replace('DATE_FORMAT(', 'DATE_FORMAT(DATE_ADD(', $working);
$working .= ', INTERVAL ' . $this->_timeZone . ' HOUR)';
}
else if ($this->_timeZone < 0)
{
$working = str_replace('DATE_FORMAT(', 'DATE_FORMAT(DATE_SUB(', $working);
$working .= ', INTERVAL ' . ($this->_timeZone * -1) . ' HOUR)';
}
}
$newQuery .= $working;
}
$query = $newQuery;
/* Replace m-d-y dates with d-m-y dates if we're in dmy mode. */
if ($this->_dateDMY)
{
$query = str_replace('%m-%d-%y', '%d-%m-%y', $query);
$query = str_replace('%m-%d-%Y', '%d-%m-%Y', $query);
$query = str_replace('%m/%d/%Y', '%d/%m/%Y', $query);
$query = str_replace('%m/%d/%y', '%d/%m/%y', $query);
}
return $query;
}
/**
public function beginTransaction() { if (!$this->_inTransaction) { // Ignore errors (if called for MyISAM, for example) $this->query('BEGIN', true); return ($this->_inTransaction = true); } else { // Already in a transaction return false; } }
public function commitTransaction() { if ($this->_inTransaction) { $this->query('COMMIT', true); $this->_inTransaction = false; return true; } else { // We're not in a transaction return false; } }
public function rollbackTransaction() { if ($this->_inTransaction) { $this->query('ROLLBACK', true); $this->_inTransaction = false; return true; } else { // We're not in a transaction return false; } } }
?>
duplicate of #171
Will be resolved once #362 is accepted.
OpenCATS uses PHP 5.X. PHP 7 is available, so it would be nice to upgrade code to be compliant to this version.