/** A PHP class to access MySQL database with convenient methods
* in an object oriented way, and with a powerful debug system.\n
* Licence: LGPL \n
* Web site: http://slaout.linux62.org/
* @version 1.0
* @author Sébastien Laoût (slaout@linux62.org)
* Upgraded for PHP7 by Carles Melgarejo (Malabars)
*/
class DB
{
/** Put this variable to true if you want ALL queries to be debugged by default:
*/
var $defaultDebug = false;
/** INTERNAL: The start time, in miliseconds.
*/
var $mtStart;
/** INTERNAL: The number of executed queries.
*/
var $nbQueries;
/** INTERNAL: The last result ressource of a query().
*/
var $lastResult;
/** INTERNAL: Connection to database.(PHP7)
*/
var $dbhandle;
/** Connect to a MySQL database to be able to use the methods below.
*/
function __construct($base, $server, $user, $pass)//Change function DB to function __construct (PHP7)
{
$this->mtStart = $this->getMicroTime();
$this->nbQueries = 0;
$this->lastResult = NULL;
/* Change the line :
* @mysqli_connect($server, $user, $pass) or die('Server connexion not possible.');
* to
* $this->dbhandle = mysqli_connect($server, $user, $pass) or die("Server connexion not possible.");
* to adequate to PHP7
*/
$this->dbhandle = mysqli_connect($server, $user, $pass)
or die("Server connexion not possible.");
#mysqli_set_charset($this->dbhandle, "utf8mb4");
mysqli_select_db($this->dbhandle,$base) //Change mysqli_select_db($base) (deprecated) to mysqli_select_db($this->dbhandle,$base) (PHP7)
or die('Database connexion not possible.');
}
/** Query the database.
* @param $query The query.
* @param $debug If true, it output the query and the resulting table.
* @return The result of the query, to use with fetchNextObject().
*/
function query($query, $debug = -1)
{
$this->nbQueries++;
$this->lastResult = mysqli_query($this->dbhandle,$query) or $this->debugAndDie($query);//Change mysql_query($query) (deprecated) to mysqli_query($this->dbhandle,$query) (PHP7)
$this->debug($debug, $query, $this->lastResult);
return $this->lastResult;
}
/** Do the same as query() but do not return nor store result.\n
* Should be used for INSERT, UPDATE, DELETE...
* @param $query The query.
* @param $debug If true, it output the query and the resulting table.
*/
function execute($query, $debug = -1)
{
$this->nbQueries++;
mysqli_query($this->dbhandle,$query) or $this->debugAndDie($query);//Change mysql_query($query) (deprecated) to mysqli_query($this->dbhandle,$query) (PHP7)
$this->debug($debug, $query);
}
/** Convenient method for mysqli_fetch_object().
* @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used.
* @return An object representing a data row.
*/
function fetchNextObject($result = NULL)
{
if ($result == NULL)
$result = $this->lastResult;
if ($result == NULL || mysqli_num_rows($result) < 1)//Change mysql_num_rows($result) (deprecated) to mysqli_num_rows($result) (PHP7)
return NULL;
else
return mysqli_fetch_object($result);//Change mysql_fetch_object($result) (deprecated) to mysqli_fetch_object($result) (PHP7)
}
/** Get the number of rows of a query.
* @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used.
* @return The number of rows of the query (0 or more).
*/
function numRows($result = NULL)
{
if ($result == NULL)
return mysqli_num_rows($this->lastResult);//Change mysql_num_rows($this->lastResult) (deprecated) to mysqli_num_rows($this->lastResult) (PHP7)
else
return mysqli_num_rows($result);
}
/** Get the result of the query as an object. The query should return a unique row.\n
* Note: no need to add "LIMIT 1" at the end of your query because
* the method will add that (for optimisation purpose).
* @param $query The query.
* @param $debug If true, it output the query and the resulting row.
* @return An object representing a data row (or NULL if result is empty).
*/
function queryUniqueObject($query, $debug = -1)
{
$query = "$query LIMIT 1";
$this->nbQueries++;
$result = mysqli_query($this->dbhandle,$query) or $this->debugAndDie($query);//Change mysql_query($query) (deprecated) to mysqli_query($this->dbhandle,$query) (PHP7)
$this->debug($debug, $query, $result);
return mysqli_fetch_object($result);//Change mysql_fetch_object($result) (deprecated) to mysqli_fetch_object($result) (PHP7)
}
/** Get the result of the query as value. The query should return a unique cell.\n
* Note: no need to add "LIMIT 1" at the end of your query because
* the method will add that (for optimisation purpose).
* @param $query The query.
* @param $debug If true, it output the query and the resulting value.
* @return A value representing a data cell (or NULL if result is empty).
*/
function queryUniqueValue($query, $debug = -1)
{
$query = "$query LIMIT 1";
$this->nbQueries++;
$result = mysqli_query($this->dbhandle,$query) or $this->debugAndDie($query);//Change mysql_query($query) (deprecated) to mysqli_query($this->dbhandle,$query) (PHP7)
$line = mysqli_fetch_row($result);//Change mysql_fetch_row($result) (deprecated) to mysqli_fetch_row($result) (PHP7)
$this->debug($debug, $query, $result);
return $line[0];
}
/** Get the maximum value of a column in a table, with a condition.
* @param $column The column where to compute the maximum.
* @param $table The table where to compute the maximum.
* @param $where The condition before to compute the maximum.
* @return The maximum value (or NULL if result is empty).
*/
function maxOf($column, $table, $where)
{
return $this->queryUniqueValue("SELECT MAX(`$column`) FROM `$table` WHERE $where");
}
/** Get the maximum value of a column in a table.
* @param $column The column where to compute the maximum.
* @param $table The table where to compute the maximum.
* @return The maximum value (or NULL if result is empty).
*/
function maxOfAll($column, $table)
{
return $this->queryUniqueValue("SELECT MAX(`$column`) FROM `$table`");
}
/** Get the count of rows in a table, with a condition.
* @param $table The table where to compute the number of rows.
* @param $where The condition before to compute the number or rows.
* @return The number of rows (0 or more).
*/
function countOf($table, $where)
{
return $this->queryUniqueValue("SELECT COUNT(*) FROM `$table` WHERE $where");
}
/** Get the count of rows in a table.
* @param $table The table where to compute the number of rows.
* @return The number of rows (0 or more).
*/
function countOfAll($table)
{
return $this->queryUniqueValue("SELECT COUNT(*) FROM `$table`");
}
/** Internal function to debug when MySQL encountered an error,
* even if debug is set to Off.
* @param $query The SQL query to echo before diying.
*/
function debugAndDie($query)
{
$this->debugQuery($query, "Error");
die("
".mysqli_error($this->dbhandle)."
");//Change mysql_error() (deprecated) to mysqli_error($this->dbhandle) (PHP7)
}
/** Internal function to debug a MySQL query.\n
* Show the query and output the resulting table if not NULL.
* @param $debug The parameter passed to query() functions. Can be boolean or -1 (default).
* @param $query The SQL query to debug.
* @param $result The resulting table of the query, if available.
*/
function debug($debug, $query, $result = NULL)
{
if ($debug === -1 && $this->defaultDebug === false)
return;
if ($debug === false)
return;
$reason = ($debug === -1 ? "Default Debug" : "Debug");
$this->debugQuery($query, $reason);
if ($result == NULL)
echo "Number of affected rows: ".mysqli_affected_rows($this->dbhandle)."
";//Change mysql_affected_rows() (deprecated) to mysqli_affected_rows($this->dbhandle) (PHP7)
else
$this->debugResult($result);
}
/** Internal function to output a query for debug purpose.\n
* Should be followed by a call to debugResult() or an echo of "".
* @param $query The SQL query to debug.
* @param $reason The reason why this function is called: "Default Debug", "Debug" or "Error".
*/
function debugQuery($query, $reason = "Debug")
{
$color = ($reason == "Error" ? "red" : "orange");
echo "".
"
".
"$reason: ".
"".htmlentities($query)."
";
}
/** Internal function to output a table representing the result of a query, for debug purpose.\n
* Should be preceded by a call to debugQuery().
* @param $result The resulting table of the query.
*/
function debugResult($result)
{
echo "
".
"";
$numFields = mysqli_num_fields($result);//Change mysql_num_fields($result) (deprecated) to mysqli_num_fields($result) (PHP7)
// BEGIN HEADER
$tables = array();
$nbTables = -1;
$lastTable = "";
$fields = array();
$nbFields = -1;
while ($column = mysqli_fetch_field($result)) {//Change mysql_fetch_field($result) (deprecated) to mysqli_fetch_field($result) (PHP7)
if ($column->table != $lastTable) {
$nbTables++;
$tables[$nbTables] = array("name" => $column->table, "count" => 1);
} else
$tables[$nbTables]["count"]++;
$lastTable = $column->table;
$nbFields++;
$fields[$nbFields] = $column->name;
}
for ($i = 0; $i <= $nbTables; $i++)
echo "| ".$tables[$i]["name"]." | ";
echo "";
echo "";
for ($i = 0; $i <= $nbFields; $i++)
echo "".$fields[$i]." | ";
echo "";
// END HEADER
while ($row = mysqli_fetch_array($result)) {//Change mysql_fetch_array($result) (deprecated) to mysqli_fetch_array($result) (PHP7)
echo "";
for ($i = 0; $i < $numFields; $i++)
echo "| ".htmlentities($row[$i])." | ";
echo "
";
}
echo "
";
$this->resetFetch($result);
}
/** Get how many time the script took from the begin of this object.
* @return The script execution time in seconds since the
* creation of this object.
*/
function getExecTime()
{
return round(($this->getMicroTime() - $this->mtStart) * 1000) / 1000;
}
/** Get the number of queries executed from the begin of this object.
* @return The number of queries executed on the database server since the
* creation of this object.
*/
function getQueriesCount()
{
return $this->nbQueries;
}
/** Go back to the first element of the result line.
* @param $result The resssource returned by a query() function.
*/
function resetFetch($result)
{
if (mysqli_num_rows($result) > 0)//Change mysql_num_rows($result) (deprecated) to mysqli_num_rows($result) (PHP7)
mysqli_data_seek($result, 0);//Change mysql_data_seek($result, 0) (deprecated) to mysqli_data_seek($result, 0) (PHP7)
}
/** Get the id of the very last inserted row.
* @return The id of the very last inserted row (in any table).
*/
function lastInsertedId()
{
return mysqli_insert_id($this->dbhandle);//Change mysql_insert_id() (deprecated) to mysqli_insert_id($this->dbhandle) (PHP7)
}
/** Close the connexion with the database server.\n
* It's usually unneeded since PHP do it automatically at script end.
*/
function close()
{
mysqli_close($this->dbhandle);//Change mysql_close() (deprecated) to mysqli_close($this->dbhandle) (PHP7)
}
/** Internal method to get the current time.
* @return The current time in seconds with microseconds (in float format).
*/
function getMicroTime()
{
list($msec, $sec) = explode(' ', microtime());
return floor($sec / 1000) + $msec;
}
} // class DB
?>
global $webPage, $webPageSubmenu;
// Main menu
$webPage[0]['ca'] = "biografia";
$webPage[0]['es'] = "la-biografia";
$webPage[0]['en'] = "biography";
$webPage[0]['de'] = "biographie";
$webPage[1]['ca'] = "obra";
$webPage[1]['es'] = "la-obra";
$webPage[1]['en'] = "works";
$webPage[1]['de'] = "werk";
$webPage[2]['ca'] = "obra-literaria";
$webPage[2]['es'] = "la-obra-literaria";
$webPage[2]['en'] = "literary-works";
$webPage[2]['de'] = "literarisches-werk";
$webPage[3]['ca'] = "obra-plastica";
$webPage[3]['es'] = "la-obra-plastica";
$webPage[3]['en'] = "pictorial-works";
$webPage[3]['de'] = "malerei";
$webPage[4]['ca'] = "traduccions";
$webPage[4]['es'] = "traducciones";
$webPage[4]['en'] = "translations";
$webPage[4]['de'] = "ubersetzungen";
$webPage[5]['ca'] = "la-fundacio";
$webPage[5]['es'] = "la-fundacion";
$webPage[5]['en'] = "foundation";
$webPage[5]['de'] = "stiftung";
$webPage[6]['ca'] = "memories";
$webPage[6]['es'] = "memorias";
$webPage[6]['en'] = "the-memories";
$webPage[6]['de'] = "erinnerungen";
$webPage[7]['ca'] = "premis-i-ajuts";
$webPage[7]['es'] = "premios-y-ayudas";
$webPage[7]['en'] = "awards-and-grants";
$webPage[7]['de'] = "preise-und-fprdermittel";
$webPage[8]['ca'] = "publicacions";
$webPage[8]['es'] = "publicaciones";
$webPage[8]['en'] = "publications";
$webPage[8]['de'] = "veroffentlichungen";
$webPage[9]['ca'] = "rutes-literaries";
$webPage[9]['es'] = "las-rutas-literarias";
$webPage[9]['en'] = "literary-tours";
$webPage[9]['de'] = "Literarische-Wege";
$webPage[10]['ca'] = "arxiu";
$webPage[10]['es'] = "archivo";
$webPage[10]['en'] = "archive";
$webPage[10]['de'] = "archiv";
$webPage[11]['ca'] = "biblioteca";
$webPage[11]['es'] = "la-biblioteca";
$webPage[11]['en'] = "library";
$webPage[11]['de'] = "bibliothek";
$webPage[12]['ca'] = "enllacos-interes";
$webPage[12]['es'] = "enlaces-interes";
$webPage[12]['en'] = "useful-links";
$webPage[12]['de'] = "links";
$webPage[13]['ca'] = "contacte";
$webPage[13]['es'] = "contacto";
$webPage[13]['en'] = "contact-us";
$webPage[13]['de'] = "kontakt";
$webPage[14]['ca'] = "informacio-legal";
$webPage[14]['es'] = "aviso-legal";
$webPage[14]['en'] = "legal-advice";
$webPage[14]['de'] = "rechtliche-hinweise";
$webPage[15]['ca'] = "politica-cookies";
$webPage[15]['es'] = "nuestra-politica-cookies";
$webPage[15]['en'] = "cookies-policy";
$webPage[15]['de'] = "weitere-informationen";
$webPage[16]['ca'] = "error";
$webPage[16]['es'] = "error";
$webPage[16]['en'] = "error";
$webPage[16]['de'] = "error";
$webPage[17]['ca'] = "resultats-arxiu";
$webPage[17]['es'] = "resultados-archivo";
$webPage[17]['en'] = "archive-results";
$webPage[17]['de'] = "ergebnisdatei";
$webPage[18]['ca'] = "resultats-biblioteca";
$webPage[18]['es'] = "resultados-biblioteca";
$webPage[18]['en'] = "library-results";
$webPage[18]['de'] = "bibliotheksergebnisse";
$webPage[19]['ca'] = "cerca";
$webPage[19]['es'] = "buscador";
$webPage[19]['en'] = "search";
$webPage[19]['de'] = "suche";
$webPage[20]['ca'] = "aloma";
/*
$webPage[20]['es'] = "aloma-es";
$webPage[20]['en'] = "aloma-en";
$webPage[20]['de'] = "aloma-de";
*/
$webPage[20]['es'] = "";
$webPage[20]['en'] = "";
$webPage[20]['de'] = "";
$webPage[21]['ca'] = "aloma-centres-educacio";
/*
$webPage[21]['es'] = "aloma-centres-educacio";
$webPage[21]['en'] = "aloma-centres-educacio";
$webPage[21]['de'] = "aloma-centres-educacio";
*/
$webPage[21]['es'] = "";
$webPage[21]['en'] = "";
$webPage[21]['de'] = "";
$webPage[22]['ca'] = "aloma-biblioteques";
/*
$webPage[22]['es'] = "aloma-biblioteques";
$webPage[22]['en'] = "aloma-biblioteques";
$webPage[22]['de'] = "aloma-biblioteques";
*/
$webPage[22]['es'] = "";
$webPage[22]['en'] = "";
$webPage[22]['de'] = "";
$webPage[23]['ca'] = "aloma-productes";
/*
$webPage[23]['es'] = "aloma-productes";
$webPage[23]['en'] = "aloma-productes";
$webPage[23]['de'] = "aloma-productes";
*/
$webPage[23]['es'] = "";
$webPage[23]['en'] = "";
$webPage[23]['de'] = "";
$webPage[24]['ca'] = "aloma-projectes";
/*
$webPage[24]['es'] = "aloma-projectes";
$webPage[24]['en'] = "aloma-projectes";
$webPage[24]['de'] = "aloma-projectes";
*/
$webPage[24]['es'] = "";
$webPage[24]['en'] = "";
$webPage[24]['de'] = "";
$webPage[25]['ca'] = "login";
$webPage[25]['es'] = "login";
$webPage[25]['en'] = "login";
$webPage[25]['de'] = "login";
$webPage[26]['ca'] = "logout";
$webPage[26]['es'] = "logout";
$webPage[26]['en'] = "logout";
$webPage[26]['de'] = "logout";
$webPage[27]['ca'] = "memories";
$webPage[27]['es'] = "memorias";
$webPage[27]['en'] = "memories-en";
$webPage[27]['de'] = "zusammenfassende-berichte";
$webPage[28]['ca'] = "exposicions";
$webPage[28]['es'] = "exposiciones";
$webPage[28]['en'] = "expositions";
$webPage[28]['de'] = "ausstellungen";
$webPage[29]['ca'] = "espais";
$webPage[29]['es'] = "espacios";
$webPage[29]['en'] = "public-spaces";
$webPage[29]['de'] = "bereiche";
$webPage[30]['ca'] = "transparencia";
$webPage[30]['es'] = "";
$webPage[30]['en'] = "";
$webPage[30]['de'] = "";
$webPage[31]['ca'] = "ajax-traduccions";
$webPage[31]['es'] = "ajax-traduccions-es";
$webPage[31]['en'] = "ajax-traduccions-en";
$webPage[31]['de'] = "ajax-traduccions-de";
$webPage[32]['ca'] = "ajax-traduccions-search";
$webPage[32]['es'] = "ajax-traduccions-search";
$webPage[32]['en'] = "ajax-traduccions-search";
$webPage[32]['de'] = "ajax-traduccions-search";
$webPage[33]['ca'] = "posteritat-escriptors-catalans";
$webPage[33]['es'] = "posteridad-escritores-catalanes";
$webPage[33]['en'] = "posterity-catalan-writers";
$webPage[33]['de'] = "posteritat-escriptors-catalans";
$webPage[34]['ca'] = "ajax-traduccions2";
$webPage[34]['es'] = "ajax-traduccions2-es";
$webPage[34]['en'] = "ajax-traduccions2-en";
$webPage[34]['de'] = "ajax-traduccions2-de";
$webPage[35]['ca'] = "ajax-traduccions3";
$webPage[35]['es'] = "ajax-traduccions3-es";
$webPage[35]['en'] = "ajax-traduccions3-en";
$webPage[35]['de'] = "ajax-traduccions3-de";
$webPage[36]['ca'] = "espai-Rodoreda";
$webPage[36]['es'] = "espai-Rodoreda-es";
$webPage[36]['en'] = "espai-Rodoreda-en";
$webPage[36]['de'] = "espai-Rodoreda-de";
$webPage[37]['ca'] = "inspiracio";
$webPage[37]['es'] = "inspiracion";
$webPage[37]['en'] = "inspiration";
$webPage[37]['de'] = "inspiration-de";
?>
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/html/iec/fundacions/www.mercerodoreda.cat/public_html/application/run.php:60
Stack trace:
#0 {main}
thrown in /var/www/html/iec/fundacions/www.mercerodoreda.cat/public_html/application/run.php on line 60