Mysql --> mysqli

Fermé
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024 - 16 nov. 2015 à 17:31
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024 - 19 nov. 2015 à 18:39
Bonjour.
Je recherche de l'aide afin de créer un site de jeu d'échecs.
Je possède les codes sources mais ceux ci sont obsolètes à cause de l'API mysql qui doit être remplacé par mysqli ou PDO pour fonctionner sur mon serveur distant.
(Fonctionne en local sous wamp 2.5).
Merci d'avance.

5 réponses

jordane45 Messages postés 38254 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 octobre 2024 4 692
16 nov. 2015 à 18:59
Bonjour,

Et quelle est la question ?
Quel est le souci au juste ?
Quel code te pose problème ?
Qu'as tu essayé de faire ?


PS: Merci de bien vouloir utiliser la coloration syntaxique (les balises de code) lorsque tu postes du code sur le forum.
Explications disponibles ici :
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code


PS² : Perso... je préfère la PDO...
Mais vu que tu as déjà du code en mysql ... la conversion en mysqli sera sûrement plus simple.
.
0
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024
16 nov. 2015 à 19:55
Merci pour ta réponse rapide.

Il s'agirait de modification minimes me semble t-il.
Voici le message que j'ai reçu de la part du créateur de ces codes:
Not sure exactly what you're asking me, but to use the mysqli extension, all you need to do is to edit the mysql.class.php file and replace mysql_* with mysqli_* (with a few minor adjustments for functions that are a bit different)
That should get you what you want.
Sorry I can't be of more assistance.

Ne sais pas exactement ce que vous me demandez , mais pour utiliser l'extension mysqli , tout ce que vous devez faire est de modifier le fichier de mysql.class.php et remplacer mysql_ * avec mysqli_ * ( avec quelques ajustements mineurs pour les fonctions qui sont un peu différent )
Cela devrait vous permetre d' obtenir ce que vous voulez .
Désolé je ne peux pas être plus d'aide .


Et donc voici le fichier nommé config.inc.php :
<?php

/* Database settings */
/* ----------------- */
$CFG_HOSTNAME = 'nom hôte de la BdD';
$CFG_USERNAME = 'username';
$CFG_PASSWORD = 'password';
$CFG_DATABASE = 'Base de Données';


/* Table settings */
/* -------------- */
$prefix = 'wc2_'; // table name prefix

define('T_CHAT' , $prefix . 'chat'); // the in-game chat/personal notes table
define('T_GAME' , $prefix . 'game'); // the game data table
define('T_HISTORY' , $prefix . 'history'); // the moves history table
define('T_MESSAGE' , $prefix . 'message'); // the game message table
define('T_PLAYER' , $prefix . 'player'); // the player data table
define('T_STAT' , $prefix . 'stat'); // the stats table
define('T_TALK' , $prefix . 'talk'); // the player messaging table
define('T_TALK_GLUE' , $prefix . 'talk_glue'); // the message glue table


/* Root Admin setting */
/* ------------------ */
$CFG_ROOT_ADMIN = 'yourname'; // Permanent admin username (case-sensitive)


/* Server / Site settings */
/* ---------------------- */

/*
--- PLEASE READ ---

this first setting is the color theme for your webchess installation
look inside the /css directory and you will find several css files with a
filename like c_{color_name}.css. pick one, and enter that name here, or you can easily
create your own, using one of the included styles as a guide.
if you do create your own, please add a pull request to my repo at
https://github.com/benjamw/chess/ so that others may have access to it.
  • / $CFG_COLOR_CSS = 'c_green_black.css'; // the name of the color css file you wish to use (in the /css directory) $CFG_MAINPAGE = 'http://yoursite.com/webchess/'; // The home page of the webchess script (include closing / ) $CFG_SITENAME = 'Your Site Name'; // The name of your website $CFG_SESSIONTIMEOUT = 0; // Number of minutes before session timeout (0 to disable) $CFG_EXPIREGAME = 45; // Number of days before untouched games are deleted (0 to disable) $CFG_EXPIREUSERS = 30; // Number of days before untouched accounts are deleted (0 to disable) $CFG_MINAUTORELOAD = 15; // Minimum number of secs between automatic page reloads (0 to disable) $CFG_USEEMAIL = true; // SMTP operations. Test it before putting it into production $CFG_MAILADDRESS = 'your.name@yoursite.com'; // Email address people see when receiving WebChess generated mail $CFG_MAXUSERS = 0; // Maximum number of users allowed (0 to disable) $CFG_CHANGEUSERNAME = false; // Whether a user can change their username from the main menu $CFG_NEWUSERS = true; // Whether a new user can register $CFG_LONGDATE = 'F j, Y \&\n\b\s\p\;g:i a'; // PHP date format $CFG_SHORTDATE = 'Y.m.d H:i'; // PHP date format $CFG_CHESS960 = true; // Whether users can play Chess960 (Fischer Random Chess) games $CFG_RATING_START = 1500; // the starting ELO rating for new players $CFG_RATING_STEP = 32; // the max ELO rating change allowed per game $CFG_NAVLINKS = '<a href="/">Home</a>'; // your site's nav links/* MySQL Error / debug settings *//* ---------------------------- */ define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below define ('DB_ERR_LOG_ERRORS' , true); // (true / false) set to true to log errors in mysql.err file define ('DB_ERR_TO' , 'your.name@yoursite.com'); // set your TO email address define ('DB_ERR_SUBJECT' , 'WebChess Query Error'); // don't really need to change this define ('DB_ERR_FROM' , $CFG_MAILADDRESS); // set your FROM email address (can be the same as TO above) define ('DB_STATS_LOG' , true); // (true / false) set to true to log query stats in mysql.err file (or database) define ('FILE_PATH_END' , 'webchess'); // set the name of the directory containing the script (with wrapping / )/* DEVELOPER USE ONLY *//* ------------------ *//* INCLUDE SOME GLOBAL INCLUDES */require_once 'mysql.class.php';require_once 'chessgame.inc.php';// instantiate the class and connect to the database$mysql = new mysql($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);$mysql->connect_select(__LINE__,__FILE__);// instantiate the chess class$chess = new ChessGame( );define('DEBUG', false); // set to true for output of debugging codeif (defined('DEBUG') && DEBUG){ ini_set('display_errors', 'On'); error_reporting(E_ALL); $mysql->error_debug = true; // Allows for error debug output $mysql->query_debug = true; // Allows for output of all queries all the time $mysql->super_debug = false; // Allows output of ALL debugging output define('JS_DEBUG', 0); // set to 1 for really annoying jvascript debug}else // do not edit the following{ ini_set('display_errors', 'Off'); error_reporting(0); // set to 0 when releasing to public $mysql->error_debug = false; // Allows for error debug output $mysql->query_debug = false; // Allows for output of all queries all the time $mysql->super_debug = false; // Allows output of ALL debugging output define('JS_DEBUG', 0);}require_once('func.global.php');require_once('func.array.php');require_once('func.bitwise.php');require_once('message.class.php');require_once('phpass.class.php');$CFG_SESSIONTIMEOUT *= 60; // convert minutes to secondsdate_default_timezone_set('UTC');?>


Et celui qu'il faut modifier aussi:
<?php
/*
+---------------------------------------------------------------------------
|
| mysql.class.php (php 4.x)
|
| by Benjam Welker
| http://iohelix.net
| based on works by W. Jason Gilmore
| http://www.wjgilmore.com; https://www.apress.com/fr
|
+---------------------------------------------------------------------------
|
| > MySQL DB Queries module
| > Date started: 2005-09-02
| > Last edited: 2006-11-14
|
| > Module Version Number: 0.9.2
|
+---------------------------------------------------------------------------
  • /class mysql{ var $linkid; // MySQL Resource ID var $host; // MySQL Host name var $user; // MySQL Username var $pswd; // MySQL password var $db; // MySQL Database var $query; // MySQL query var $query_time; // Time it took to run the query var $pass_query; // Query passed by argument var $result; // Query result var $line; // Line of query var $file; // File of query var $error; // Any error message encountered while running var $log_path; // The path to the log file var $querycount; // Total number of queries executed since class inception var $error_debug; // Allows for error debug output var $query_debug; // Allows for output of all queries all the time var $super_debug; // Allows output of ALL debugging output /* Class constructor. Initializes the host, user, pswd, db and log fields */ function mysql($host, $user, $pswd, $db, $log_path = './') { /*# # # The following was moved to the config file for # ease of use by the admin (so they don't have to config # multiple files, and only have to edit one), # but the original source was left here for those who wish # to implement this class in their own creations. # # to enable, just change /*# above to //*# and edit settings # # to disable, change //*# above to /*# # and copy-paste this section into your own config file # // BEGIN CONFIG ---------------------- define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below define ('DB_ERR_LOG_ERRORS' , true); // (true / false) set to true to log errors in mysql.err file define ('DB_ERR_TO' , 'yourname@yoursite.com'); // set your TO email address define ('DB_ERR_SUBJECT' , 'Query Error'); // don't really need to change this define ('DB_ERR_FROM' , 'yourname@yoursite.com'); // set your FROM email address (can be the same as TO above) define ('FILE_PATH_END' , '/yourscript/'); // the name of the directory containing the script (with wrapping / ) // END CONFIG ------------------------ # # end of config section removal # #*/ $this->host = $host; $this->user = $user; $this->pswd = $pswd; $this->db = $db; $this->log_path = $log_path; // each of these can be set independently as needed $this->error_debug = false; // set to true for output of errors $this->query_debug = false; // set to true for output of every query $this->super_debug = false; // set to true for other debugging output (like passed query arguments, etc.) // make sure the log path ends with / if (strrpos($this->log_path,'/') != (strlen($this->log_path) - 1)) { $this->log_path .= '/'; } } /* Connect to the MySQL database server */ function connect( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->load_arguments($args); } $this->linkid = @mysql_connect($this->host, $this->user, $this->pswd); if ( ! $this->linkid) { $this->error = mysql_errno( ).': '.mysql_error( ); $this->error_report( ); if ($this->error_debug) { echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}"; } else { die('There was a database error. An email has been sent to the system administrator.'); } } } /* Selects the MySQL Database */ function select( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->load_arguments($args); } if ( ! @mysql_select_db($this->db, $this->linkid)) { $this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid); $this->error_report( ); if ($this->error_debug) { echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}"; } else { die('There was a database error. An email has been sent to the system administrator.'); } } } /* Connects to the server AND selects the default database in one function */ function connect_select( ) { $num_args = func_num_args( ); $args = func_get_args( ); $this->clear_arguments( ); // get the arguments, if any if (0 != $num_args) { $this->load_arguments($args); } $this->connect( ); $this->select( ); } /* Execute Database Query */ function query( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); // don't clear unless we have new $this->load_arguments($args); if (false !== $this->pass_query) { $this->query = $this->pass_query; } } if ($this->super_debug) { echo 'QUERY '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } $done = true; // innocent until proven guilty // start time logging $time = microtime_float( ); $this->result = @mysql_query($this->query, $this->linkid); $this->query_time = microtime_float( ) - $time; if ($this->query_debug) { $this->query = trim(preg_replace('/\\s+/', ' ', $this->query)); echo "<div style='background:white;color:black;'><br />{$this->query} - <strong>Aff(".$this->affected_rows( ).") - {$this->file_name}: {$this->line}</strong></div>"; } if ( ! $this->result) { $this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid); $this->error_report( ); if ($this->error_debug) { echo "<div style='background:#900;color:white;'>There was an error in your query in {$this->file_name} on line {$this->line}: ERROR - {$this->error}<br />Query: {$this->query}</div>"; print_r(debug_backtrace( )); } else { $this->error = 'There was a database error. An email has been sent to the system administrator.'; } $done = false; } if ($done) { $this->querycount++; return $this->result; } return false; } /* Determine total rows affected by query */ function affected_rows( ) { $count = @mysql_affected_rows($this->linkid); return $count; } /* Determine total rows returned by query */ function num_rows( ) { $count = @mysql_num_rows($this->result); if ( ! $count) { return 0; } return $count; } /** public function insert * Insert the associative data array into the table. * $data['field_name'] = value * $data['field_name2'] = value2 * If the field name has a trailing space: $data['field_name '] * then the query will insert the data with no sanitation * or wrapping quotes (good for function calls, like NOW( )). * * @param string table name * @param array associative data array * @param string [optional] where clause (for updates) * @param bool [optional] whether or not we should replace values (true / false) * @action execute a mysql query * @return int insert id for row */ function insert($table, $data_array, $where = '', $replace = false) { $where = trim($where); $replace = (bool) $replace; if ('' == $where) { $query = (false == $replace) ? ' INSERT ' : ' REPLACE '; $query .= ' INTO '; } else { $query = ' UPDATE '; } $query .= '`'.$table.'`'; if ( ! is_array($data_array)) { throw new MySQLException(__METHOD__.': Trying to insert non-array data'); } else { $query .= ' SET '; foreach ($data_array as $field => $value) { if (is_null($value)) { $query .= " `{$field}` = NULL , "; } elseif (' ' == substr($field, -1, 1)) { // i picked a trailing space because it's an illegal field name in MySQL $field = trim($field); $query .= " `{$field}` = {$value} , "; } else { $query .= " `{$field}` = '".sani($value)."' , "; } } $query = substr($query, 0, -2).' '; // remove the last comma (but preserve those spaces) } $query .= ' '.$where.' '; $this->query = $query; $return = $this->query( ); if ('' == $where) { return $this->fetch_insert_id( ); } else { return $return; } } /** public function multi_insert * Insert the array of associative data arrays into the table. * $data[0]['field_name'] = value * $data[0]['field_name2'] = value2 * $data[0]['DBWHERE'] = where clause [optional] * $data[1]['field_name'] = value * $data[1]['field_name2'] = value2 * $data[1]['DBWHERE'] = where clause [optional] * * @param string table name * @param array associative data array * @param bool [optional] whether or not we should replace values (true / false) * @action execute multiple mysql queries * @return array insert ids for rows (with original keys preserved) */ function multi_insert($table, $data_array, $replace = false) { if ( ! is_array($data_array)) { throw new MySQLException(__METHOD__.': Trying to multi-insert non-array data'); } else { $result = array( ); foreach ($data_array as $key => $row) { $where = (isset($row['DBWHERE'])) ? $row['DBWHERE'] : ''; unset($row['DBWHERE']); $result[$key] = $this->insert($table, $row, $where, $replace); } } return $result; } /** public function delete * Delete the row from the table * * @param string table name * @param string where clause * @action execute a mysql query * @return result */ function delete($table, $where) { $query = " DELETE FROM `{$table}` {$where} "; $this->query = $query; try { return $this->query( ); } catch (MySQLException $e) { throw $e; } } /** public function multi_delete * Delete the array of data from the table. * $table[0] = table name * $table[1] = table name * * $where[0] = where clause * $where[1] = where clause * * If recursive is true, all combinations of table name * and where clauses will be executed. * * If only one table name is set, that table will * be used for all of the queries, looping through * the where array * * If only one where clause is set, that where clause * will be used for all of the queries, looping through * the table array * * @param mixed table name array or single string * @param mixed where clause array or single string * @param bool optional recursive (default false) * @action execute multiple mysql queries * @return array results */ function multi_delete($table_array, $where_array, $recursive = false) { if ( ! is_array($table_array)) { $recursive = false; $table_array = (array) $table_array; } if ( ! is_array($where_array)) { $recursive = false; $where_array = (array) $where_array; } if ($recursive) { foreach ($table_array as $table) { foreach ($where_array as $where) { $result[] = $this->delete($table, $where); } } } else { if (count($table_array) == count($where_array)) { for ($i = 0, $count = count($table_array); $i < $count; ++$i) { $result[] = $this->delete($table_array[$i], $where_array[$i]); } } elseif (1 == count($table_array)) { $table = $table_array[0]; foreach ($where_array as $where) { $result[] = $this->delete($table, $where); } } elseif (1 == count($where_array)) { $where = $where_array[0]; foreach ($table_array as $table) { $result[] = $this->delete($table, $where); } } else { throw new MySQLException(__METHOD__.': Trying to multi-delete with incompatible array sizes'); } } return $result; } /* Return query result row as an object */ function fetch_object( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_OBJECT '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $row = @mysql_fetch_object($this->result); return $row; } /* Return query result row as an indexed array */ function fetch_row( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_ROW '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $row = @mysql_fetch_row($this->result); return $row; } /* Return query result row as an associative array */ function fetch_assoc( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_ASSOC '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $row = @mysql_fetch_assoc($this->result); return $row; } /* Return query result row as an associative array and an indexed array */ function fetch_both( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_BOTH '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $row = @mysql_fetch_array($this->result, MYSQL_BOTH); return $row; } /* Return query result as an array of arrays */ function fetch_array( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_ARRAY '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $arr = array( ); while ($row = @mysql_fetch_array($this->result)) { $arr[] = $row; } return $arr; } /* Return query result as an array of single values */ function fetch_value_array( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_VALUE_ARRAY '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $arr = array( ); while ($row = @mysql_fetch_row($this->result)) { $arr[] = $row[0]; } return $arr; } /* Return single query result value */ function fetch_value( ) { $num_args = func_num_args( ); $args = func_get_args( ); // get the arguments, if any if (0 != $num_args) { $this->clear_arguments( ); $this->load_arguments($args); } if ($this->super_debug) { echo 'FETCH_VALUE '; echo '<pre>'; print_r($this->get_arguments( )); echo '</pre>'; } if (false !== $this->pass_query) { $this->query = $this->pass_query; $this->query( ); } $row = @mysql_fetch_row($this->result); return $row[0]; } /* Return the total number of queries executed during the lifetime of this object */ function num_queries( ) { return $this->querycount; } /* get the id for the previous INSERT command */ function fetch_insert_id( ) { return @mysql_insert_id($this->linkid); } /* get the errors, if any */ function fetch_error( ) { return $this->error; } /* report the errors to the admin */ function error_report( ) { // generate an error report and then act according to configuration $error_report = "An error has been generated by the server.\nFollowing is the debug information:\n\n"; $error_report .= " * File: {$this->file_name}\n"; $error_report .= " * Line: {$this->line}\n"; $error_report .= " * Error: {$this->error}\n"; $error_report_short = "\n" . date('Y-m-d H:i:s') . " Error in {$this->file_name} on line {$this->line}: ERROR - {$this->error}"; // if a database query caused the error, show the query if ('' != $this->query) { $error_report .= " * Query: {$this->query}\n"; $error_report_short .= " [sql={$this->query}]"; } // send the error as email if set if (DB_ERR_EMAIL_ERRORS) { mail(DB_ERR_TO, trim(DB_ERR_SUBJECT), $error_report."\n\n".safe_var_export(debug_backtrace( ))."\n\n\$GLOBALS = ".safe_var_export($GLOBALS), 'From: '.DB_ERR_FROM."\r\n"); } // log the error (remove line breaks and multiple concurrent spaces) $this->logger(trim(preg_replace('/\\s+/', ' ', $error_report_short))."\n"); } /* log any errors */ function logger($report) { if (DB_ERR_LOG_ERRORS) { $log = $this->log_path . "mysql.err"; $fp = fopen($log,'a+'); fwrite($fp,$report); @chmod($log, 0777); fclose($fp); } } /* extract the arguments */ function load_arguments($args) { foreach ($args as $arg) { if ($this->super_debug) { echo '<hr />arg = ('; echo stripslashes(var_export($arg, true)).') - '; echo 'is_line('.var_export(is_int($arg), true).') '; echo 'is_file('.var_export(('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg)), true).') '; echo 'is_database('.var_export(is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' ')), true).') '; echo 'is_query('.var_export(0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg), true).') --- '; } if (is_int($arg)) // it's an integer { if ($this->super_debug) echo 'LINE - '; $this->line = $arg; if ($this->super_debug) echo $this->line; } elseif (('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg))) // the string begins with '/' or a drive letter { if ($this->super_debug) echo 'FILE - '; $this->file_name = substr($arg, strpos($arg, FILE_PATH_END)); if ($this->super_debug) echo $this->file_name; } elseif (is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' '))) // there are no spaces { if ($this->super_debug) echo 'DATABASE - '; $this->db = $arg; if ($this->super_debug) echo $this->db; } elseif (0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg)) // it begins with a query word { if ($this->super_debug) echo 'QUERY - '; $this->pass_query = $arg; if ($this->super_debug) echo $this->pass_query; } else { if ($this->super_debug) echo 'UNKNOWN - '; $arg_dump = var_export($arg, true); $this->error = 'Unknown argument found: ' . $arg_dump; if ($this->super_debug) echo $this->error; } } // wait until after all arguments are entered before outputting error // because the error may happen on the first argument and the other // arguments have important error report data (it's what they're for) if ('Unknown argument' == substr((string) $this->error, 0, 16)) { $this->error_report( ); } if ($this->super_debug) {echo'<pre>';print_r($this->get_arguments( ));echo'</pre>';} } /* clear the arguments */ function clear_arguments( ) { // don't clear query or db as we may use them later $this->line = false; $this->file_name = false; $this->error = false; $this->pass_query = false; } /* return the arguments */ function get_arguments( ) { $args['line'] = $this->line; $args['file'] = $this->file_name; $args['error'] = $this->error; $args['query'] = $this->pass_query; return $args; }} // end of mysql class/* +--------------------------------------------------------------------------- | > Extra SQL Functions +---------------------------------------------------------------------------*//* escape the data before it gets queried into the database */function sani($data){ if (is_array($data)) { return array_map('sani', $data); } else { if (get_magic_quotes_gpc( )) { $data = stripslashes($data); }# $data = htmlentities($data, ENT_NOQUOTES); // convert html to &html; if (function_exists('mysql_real_escape_string')) { $data = mysql_real_escape_string($data); // php 4.3.0+ } else { $data = mysql_escape_string($data); // php 4.0+ } return $data; }}if ( ! function_exists('microtime_float')){ function microtime_float( ) { list($usec, $sec) = explode(' ', microtime( )); return ((float)$usec + (float)$sec); }}function safe_var_export($var){ if ( ! is_array($var)) { return var_export($var, true); } foreach ($var as $key => $data) { if (('GLOBALS' == $key) || ($data == $var)) { $var[$key] = 'RECURSION'; continue; } } return var_export($var, true);}?>


Et voici ce que j'ai réussi à modifier de façon efficace je pense dans le fichier config.inc.php

// instantiate the class and connect to the database
$mysql = new mysqli($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
$mysql->connect_select(__LINE__,__FILE__);

Je pense que c'est la seule modification en ce qui concerne ce fichier.
Pour l'autre j'ai cherché mais je n'ai pas trouvé.
Alors si tu peux me corrigé les codes, se serait bien sympa pour que je puisse présenter mon site de jeu d'échecs pour les passionnés de ce jeu.
Merci.
Et merci pour eux.
0
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024
16 nov. 2015 à 20:00
Ma modif sur config.inc.php:
// instantiate the class and connect to the database
$mysql =  new mysqli($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
$mysql->connect_select(__LINE__,__FILE__);


Fichier d'origine config.inc.php:
<?php

/* Database settings */
/* ----------------- */
	$CFG_HOSTNAME = 'localhost';
	$CFG_USERNAME = 'root';
	$CFG_PASSWORD = '';
	$CFG_DATABASE = 'webchess';


/* Table settings */
/* -------------- */
	$prefix = 'wc2_'; // table name prefix

	define('T_CHAT'      , $prefix . 'chat'); // the in-game chat/personal notes table
	define('T_GAME'      , $prefix . 'game'); // the game data table
	define('T_HISTORY'   , $prefix . 'history'); // the moves history table
	define('T_MESSAGE'   , $prefix . 'message'); // the game message table
	define('T_PLAYER'    , $prefix . 'player'); // the player data table
	define('T_STAT'      , $prefix . 'stat'); // the stats table
	define('T_TALK'      , $prefix . 'talk'); // the player messaging table
	define('T_TALK_GLUE' , $prefix . 'talk_glue'); // the message glue table


/* Root Admin setting */
/* ------------------ */
	$CFG_ROOT_ADMIN = 'admin'; // Permanent admin username (case-sensitive)


/* Server / Site settings */
/* ---------------------- */

	/*
		  --- PLEASE READ ---

		this first setting is the color theme for your webchess installation
		look inside the /css directory and you will find several css files with a
		filename like c_{color_name}.css.  pick one, and enter that name here, or you can easily
		create your own, using one of the included styles as a guide.
		if you do create your own, please add a pull request to my repo at
		https://github.com/benjamw/chess/ so that others may have access to it.
	*/

	$CFG_COLOR_CSS      = 'c_green_black.css'; // the name of the color css file you wish to use (in the /css directory)

	$CFG_MAINPAGE       = 'localhost/webchess/'; // The home page of the webchess script (include closing / )

	$CFG_SITENAME       = 'Echecs'; // The name of your website

	$CFG_SESSIONTIMEOUT = 10; // Number of minutes before session timeout (0 to disable)

	$CFG_EXPIREGAME     = 100; // Number of days before untouched games are deleted (0 to disable)

	$CFG_EXPIREUSERS    = 100; // Number of days before untouched accounts are deleted (0 to disable)

	$CFG_MINAUTORELOAD  = 15; // Minimum number of secs between automatic page reloads (0 to disable)

	$CFG_USEEMAIL       = true; // SMTP operations.  Test it before putting it into production

	$CFG_MAILADDRESS    = 'psftxa@free.fr'; // Email address people see when receiving WebChess generated mail

	$CFG_MAXUSERS       = 0; // Maximum number of users allowed (0 to disable)

	$CFG_CHANGEUSERNAME = false; // Whether a user can change their username from the main menu

	$CFG_NEWUSERS       = true; // Whether a new user can register

	$CFG_LONGDATE       = 'F j, Y \&\n\b\s\p\;g:i a'; // PHP date format

	$CFG_SHORTDATE      = 'Y.m.d H:i'; // PHP date format

	$CFG_CHESS960       = true; // Whether users can play Chess960 (Fischer Random Chess) games

	$CFG_RATING_START   = 1500; // the starting ELO rating for new players

	$CFG_RATING_STEP    = 32; // the max ELO rating change allowed per game

	$CFG_NAVLINKS       = '<a href="/">Home</a>'; // your site's nav links



/* MySQL Error / debug settings */
/* ---------------------------- */
	define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
	define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
	define ('DB_ERR_TO'          , 'your.name@yoursite.com'); // set your TO email address
	define ('DB_ERR_SUBJECT'     , 'WebChess Query Error'); // don't really need to change this
	define ('DB_ERR_FROM'        , $CFG_MAILADDRESS); // set your FROM email address (can be the same as TO above)
	define ('DB_STATS_LOG'       , true); // (true / false) set to true to log query stats in mysql.err file (or database)
	define ('FILE_PATH_END'      , 'webchess'); // set the name of the directory containing the script (with wrapping / )



/* DEVELOPER USE ONLY */
/* ------------------ */

/* INCLUDE SOME GLOBAL INCLUDES */
require_once 'mysql.class.php';
require_once 'chessgame.inc.php';

// instantiate the class and connect to the database
$mysql = new mysql($CFG_HOSTNAME, $CFG_USERNAME, $CFG_PASSWORD, $CFG_DATABASE);
$mysql->connect_select(__LINE__,__FILE__);

// instantiate the chess class
$chess = new ChessGame( );

define('DEBUG', false); // set to true for output of debugging code

if (defined('DEBUG') && DEBUG)
{
	ini_set('display_errors', 'On');
	error_reporting(E_ALL);
	$mysql->error_debug = true; // Allows for error debug output
	$mysql->query_debug = true; // Allows for output of all queries all the time
	$mysql->super_debug = false; // Allows output of ALL debugging output
	define('JS_DEBUG', 0); // set to 1 for really annoying jvascript debug
}
else // do not edit the following
{
	ini_set('display_errors', 'Off');
	error_reporting(0); // set to 0 when releasing to public
	$mysql->error_debug = false; // Allows for error debug output
	$mysql->query_debug = false; // Allows for output of all queries all the time
	$mysql->super_debug = false; // Allows output of ALL debugging output
	define('JS_DEBUG', 0);
}

require_once('func.global.php');
require_once('func.array.php');
require_once('func.bitwise.php');
require_once('message.class.php');
require_once('phpass.class.php');

$CFG_SESSIONTIMEOUT *= 60; // convert minutes to seconds

date_default_timezone_set('UTC');



Et mysql.class.php
<?php
/*
+---------------------------------------------------------------------------
|
|   mysql.class.php (php 4.x)
|
|   by Benjam Welker
|   http://iohelix.net
|   based on works by W. Jason Gilmore
|   http://www.wjgilmore.com; http://www.apress.com
|
+---------------------------------------------------------------------------
|
|   > MySQL DB Queries module
|   > Date started: 2005-09-02
|   >  Last edited: 2006-11-14
|
|   > Module Version Number: 0.9.2
|
+---------------------------------------------------------------------------
*/

class mysql
{
	var $linkid;      // MySQL Resource ID
	var $host;        // MySQL Host name
	var $user;        // MySQL Username
	var $pswd;        // MySQL password
	var $db;          // MySQL Database
	var $query;       // MySQL query
	var $query_time;  // Time it took to run the query
	var $pass_query;  // Query passed by argument
	var $result;      // Query result
	var $line;        // Line of query
	var $file;        // File of query
	var $error;       // Any error message encountered while running
	var $log_path;    // The path to the log file
	var $querycount;  // Total number of queries executed since class inception
	var $error_debug; // Allows for error debug output
	var $query_debug; // Allows for output of all queries all the time
	var $super_debug; // Allows output of ALL debugging output



	/* Class constructor.  Initializes the host, user, pswd, db and log fields */
	function mysql($host, $user, $pswd, $db, $log_path = './')
	{

		/*#
		  #
		  # The following was moved to the config file for
		  # ease of use by the admin (so they don't have to config
		  # multiple files, and only have to edit one),
		  # but the original source was left here for those who wish
		  # to implement this class in their own creations.
		  #
		  # to enable, just change  /*#  above to  //*#  and edit settings
		  #
		  # to disable, change  //*#  above to  /*#
		  # and copy-paste this section into your own config file
		  #

		// BEGIN CONFIG ----------------------

		define ('DB_ERR_EMAIL_ERRORS', true); // (true / false) set to true to email errors to TO address below
		define ('DB_ERR_LOG_ERRORS'  , true); // (true / false) set to true to log errors in mysql.err file
		define ('DB_ERR_TO'          , 'yourname@yoursite.com'); // set your TO email address
		define ('DB_ERR_SUBJECT'     , 'Query Error'); // don't really need to change this
		define ('DB_ERR_FROM'        , 'yourname@yoursite.com'); // set your FROM email address (can be the same as TO above)
		define ('FILE_PATH_END'      , '/yourscript/'); // the name of the directory containing the script (with wrapping / )

		// END CONFIG ------------------------

		  #
		  # end of config section removal
		  #
		  #*/

		$this->host = $host;
		$this->user = $user;
		$this->pswd = $pswd;
		$this->db   = $db;
		$this->log_path = $log_path;

		// each of these can be set independently as needed
		$this->error_debug = false; // set to true for output of errors
		$this->query_debug = false; // set to true for output of every query
		$this->super_debug = false; // set to true for other debugging output (like passed query arguments, etc.)

		// make sure the log path ends with /
		if (strrpos($this->log_path,'/') != (strlen($this->log_path) - 1))
		{
			$this->log_path .= '/';
		}
	}



	/* Connect to the MySQL database server */
	function connect( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->load_arguments($args);
		}

		$this->linkid = @mysql_connect($this->host, $this->user, $this->pswd);

		if ( ! $this->linkid)
		{
			$this->error = mysql_errno( ).': '.mysql_error( );
			$this->error_report( );

			if ($this->error_debug)
			{
				echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
			}
			else
			{
				die('There was a database error. An email has been sent to the system administrator.');
			}
		}
	}



	/* Selects the MySQL Database */
	function select( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->load_arguments($args);
		}

		if ( ! @mysql_select_db($this->db, $this->linkid))
		{
			$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
			$this->error_report( );

			if ($this->error_debug)
			{
				echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
			}
			else
			{
				die('There was a database error. An email has been sent to the system administrator.');
			}
		}
	}



	/* Connects to the server AND selects the default database in one function */
	function connect_select( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		$this->clear_arguments( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->load_arguments($args);
		}

		$this->connect( );
		$this->select( );
	}



	/* Execute Database Query */
	function query( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( ); // don't clear unless we have new
			$this->load_arguments($args);

			if (false !== $this->pass_query)
			{
				$this->query = $this->pass_query;
			}
		}

		if ($this->super_debug)
		{
			echo 'QUERY ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		$done = true; // innocent until proven guilty

		// start time logging
		$time = microtime_float( );
		$this->result = @mysql_query($this->query, $this->linkid);
		$this->query_time = microtime_float( ) - $time;

		if ($this->query_debug)
		{
			$this->query = trim(preg_replace('/\\s+/', ' ', $this->query));
			echo "<div style='background:white;color:black;'><br />{$this->query} - <strong>Aff(".$this->affected_rows( ).") - {$this->file_name}: {$this->line}</strong></div>";
		}

		if ( ! $this->result)
		{
			$this->error = mysql_errno($this->linkid).': '.mysql_error($this->linkid);
			$this->error_report( );

			if ($this->error_debug)
			{
				echo "<div style='background:#900;color:white;'>There was an error in your query in {$this->file_name} on line {$this->line}: ERROR - {$this->error}<br />Query: {$this->query}</div>";
				print_r(debug_backtrace( ));
			}
			else
			{
				$this->error = 'There was a database error. An email has been sent to the system administrator.';
			}

			$done = false;
		}

		if ($done)
		{
			$this->querycount++;
			return $this->result;
		}

		return false;
	}



	/* Determine total rows affected by query */
	function affected_rows( )
	{
		$count = @mysql_affected_rows($this->linkid);
		return $count;
	}



	/* Determine total rows returned by query */
	function num_rows( )
	{
		$count = @mysql_num_rows($this->result);

		if ( ! $count)
		{
			return 0;
		}

		return $count;
	}


	/** public function insert
	 *		Insert the associative data array into the table.
	 *			$data['field_name'] = value
	 *			$data['field_name2'] = value2
	 *		If the field name has a trailing space: $data['field_name ']
	 *		then the query will insert the data with no sanitation
	 *		or wrapping quotes (good for function calls, like NOW( )).
	 *
	 * @param string table name
	 * @param array associative data array
	 * @param string [optional] where clause (for updates)
	 * @param bool [optional] whether or not we should replace values (true / false)
	 * @action execute a mysql query
	 * @return int insert id for row
	 */
	function insert($table, $data_array, $where = '', $replace = false)
	{
		$where = trim($where);
		$replace = (bool) $replace;

		if ('' == $where) {
			$query  = (false == $replace) ? ' INSERT ' : ' REPLACE ';
			$query .= ' INTO ';
		}
		else {
			$query = ' UPDATE ';
		}

		$query .= '`'.$table.'`';

		if ( ! is_array($data_array)) {
			throw new MySQLException(__METHOD__.': Trying to insert non-array data');
		}
		else {
			$query .= ' SET ';
			foreach ($data_array as $field => $value) {
				if (is_null($value)) {
					$query .=  " `{$field}` = NULL , ";
				}
				elseif (' ' == substr($field, -1, 1)) { // i picked a trailing space because it's an illegal field name in MySQL
					$field = trim($field);
					$query .= " `{$field}` = {$value} , ";
				}
				else {
					$query .= " `{$field}` = '".sani($value)."' , ";
				}
			}

			$query = substr($query, 0, -2).' '; // remove the last comma (but preserve those spaces)
		}

		$query .= ' '.$where.' ';
		$this->query = $query;
		$return = $this->query( );

		if ('' == $where) {
			return $this->fetch_insert_id( );
		}
		else {
			return $return;
		}
	}


	/** public function multi_insert
	 *		Insert the array of associative data arrays into the table.
	 *			$data[0]['field_name'] = value
	 *			$data[0]['field_name2'] = value2
	 *			$data[0]['DBWHERE'] = where clause [optional]
	 *			$data[1]['field_name'] = value
	 *			$data[1]['field_name2'] = value2
	 *			$data[1]['DBWHERE'] = where clause [optional]
	 *
	 * @param string table name
	 * @param array associative data array
	 * @param bool [optional] whether or not we should replace values (true / false)
	 * @action execute multiple mysql queries
	 * @return array insert ids for rows (with original keys preserved)
	 */
	function multi_insert($table, $data_array, $replace = false)
	{
		if ( ! is_array($data_array)) {
			throw new MySQLException(__METHOD__.': Trying to multi-insert non-array data');
		}
		else {
			$result = array( );

			foreach ($data_array as $key => $row) {
				$where = (isset($row['DBWHERE'])) ? $row['DBWHERE'] : '';
				unset($row['DBWHERE']);
				$result[$key] = $this->insert($table, $row, $where, $replace);
			}
		}

		return $result;
	}


	/** public function delete
	 *		Delete the row from the table
	 *
	 * @param string table name
	 * @param string where clause
	 * @action execute a mysql query
	 * @return result
	 */
	function delete($table, $where)
	{
		$query = "
			DELETE
			FROM `{$table}`
			{$where}
		";

		$this->query = $query;

		try {
			return $this->query( );
		}
		catch (MySQLException $e) {
			throw $e;
		}
	}


	/** public function multi_delete
	 *		Delete the array of data from the table.
	 *			$table[0] = table name
	 *			$table[1] = table name
	 *
	 *			$where[0] = where clause
	 *			$where[1] = where clause
	 *
	 *		If recursive is true, all combinations of table name
	 *		and where clauses will be executed.
	 *
	 *		If only one table name is set, that table will
	 *		be used for all of the queries, looping through
	 *		the where array
	 *
	 *		If only one where clause is set, that where clause
	 *		will be used for all of the queries, looping through
	 *		the table array
	 *
	 * @param mixed table name array or single string
	 * @param mixed where clause array or single string
	 * @param bool optional recursive (default false)
	 * @action execute multiple mysql queries
	 * @return array results
	 */
	function multi_delete($table_array, $where_array, $recursive = false)
	{
		if ( ! is_array($table_array)) {
			$recursive = false;
			$table_array = (array) $table_array;
		}

		if ( ! is_array($where_array)) {
			$recursive = false;
			$where_array = (array) $where_array;
		}

		if ($recursive) {
			foreach ($table_array as $table) {
				foreach ($where_array as $where) {
					$result[] = $this->delete($table, $where);
				}
			}
		}
		else {
			if (count($table_array) == count($where_array)) {
				for ($i = 0, $count = count($table_array); $i < $count; ++$i) {
					$result[] = $this->delete($table_array[$i], $where_array[$i]);
				}
			}
			elseif (1 == count($table_array)) {
				$table = $table_array[0];
				foreach ($where_array as $where) {
					$result[] = $this->delete($table, $where);
				}
			}
			elseif (1 == count($where_array)) {
				$where = $where_array[0];
				foreach ($table_array as $table) {
					$result[] = $this->delete($table, $where);
				}
			}
			else {
				throw new MySQLException(__METHOD__.': Trying to multi-delete with incompatible array sizes');
			}
		}

		return $result;
	}



	/* Return query result row as an object */
	function fetch_object( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_OBJECT ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$row = @mysql_fetch_object($this->result);
		return $row;
	}



	/* Return query result row as an indexed array */
	function fetch_row( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_ROW ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$row = @mysql_fetch_row($this->result);
		return $row;
	}



	/* Return query result row as an associative array */
	function fetch_assoc( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_ASSOC ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$row = @mysql_fetch_assoc($this->result);
		return $row;
	}



	/* Return query result row as an associative array and an indexed array */
	function fetch_both( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_BOTH ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$row = @mysql_fetch_array($this->result, MYSQL_BOTH);
		return $row;
	}



	/* Return query result as an array of arrays */
	function fetch_array( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_ARRAY ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$arr = array( );
		while ($row = @mysql_fetch_array($this->result))
		{
			$arr[] = $row;
		}

		return $arr;
	}



	/* Return query result as an array of single values */
	function fetch_value_array( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_VALUE_ARRAY ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$arr = array( );
		while ($row = @mysql_fetch_row($this->result))
		{
			$arr[] = $row[0];
		}

		return $arr;
	}



	/* Return single query result value */
	function fetch_value( )
	{
		$num_args = func_num_args( );
		$args     = func_get_args( );

		// get the arguments, if any
		if (0 != $num_args)
		{
			$this->clear_arguments( );
			$this->load_arguments($args);
		}

		if ($this->super_debug)
		{
			echo 'FETCH_VALUE ';
			echo '<pre>';
			print_r($this->get_arguments( ));
			echo '</pre>';
		}

		if (false !== $this->pass_query)
		{
			$this->query = $this->pass_query;
			$this->query( );
		}

		$row = @mysql_fetch_row($this->result);
		return $row[0];
	}



	/* Return the total number of queries executed during
		 the lifetime of this object                         */
	function num_queries( )
	{
		return $this->querycount;
	}



	/* get the id for the previous INSERT command */
	function fetch_insert_id( )
	{
		return @mysql_insert_id($this->linkid);
	}



	/* get the errors, if any */
	function fetch_error( )
	{
		return $this->error;
	}



	/* report the errors to the admin */
	function error_report( )
	{
		// generate an error report and then act according to configuration
		$error_report  = "An error has been generated by the server.\nFollowing is the debug information:\n\n";
		$error_report .= "   *  File: {$this->file_name}\n";
		$error_report .= "   *  Line: {$this->line}\n";
		$error_report .= "   * Error: {$this->error}\n";

		$error_report_short = "\n" . date('Y-m-d H:i:s') . " Error in {$this->file_name} on line {$this->line}: ERROR - {$this->error}";

		// if a database query caused the error, show the query
		if ('' != $this->query)
		{
			$error_report .= "   * Query: {$this->query}\n";
			$error_report_short .= " [sql={$this->query}]";
		}

		// send the error as email if set
		if (DB_ERR_EMAIL_ERRORS)
		{
			mail(DB_ERR_TO, trim(DB_ERR_SUBJECT), $error_report."\n\n".safe_var_export(debug_backtrace( ))."\n\n\$GLOBALS = ".safe_var_export($GLOBALS), 'From: '.DB_ERR_FROM."\r\n");
		}

		// log the error (remove line breaks and multiple concurrent spaces)
		$this->logger(trim(preg_replace('/\\s+/', ' ', $error_report_short))."\n");
	}



	/* log any errors */
	function logger($report)
	{
		if (DB_ERR_LOG_ERRORS)
		{
			$log = $this->log_path . "mysql.err";
			$fp = fopen($log,'a+');
			fwrite($fp,$report);
			@chmod($log, 0777);
			fclose($fp);
		}
	}



	/* extract the arguments */
	function load_arguments($args)
	{
		foreach ($args as $arg)
		{
			if ($this->super_debug)
			{
				echo '<hr />arg = (';
				echo stripslashes(var_export($arg, true)).') - ';
				echo 'is_line('.var_export(is_int($arg), true).') ';
				echo 'is_file('.var_export(('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg)), true).') ';
				echo 'is_database('.var_export(is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' ')), true).') ';
				echo 'is_query('.var_export(0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg), true).') --- ';
			}

			if (is_int($arg)) // it's an integer
			{
				if ($this->super_debug) echo 'LINE - ';
				$this->line = $arg;
				if ($this->super_debug) echo $this->line;
			}
			elseif (('/' == substr($arg, 0, 1)) || (0 != preg_match('/^\\w:/', $arg))) // the string begins with '/' or a drive letter
			{
				if ($this->super_debug) echo 'FILE - ';
				$this->file_name = substr($arg, strpos($arg, FILE_PATH_END));
				if ($this->super_debug) echo $this->file_name;
			}
			elseif (is_string($arg) && (0 != strlen($arg)) && (false === strpos($arg, ' '))) // there are no spaces
			{
				if ($this->super_debug) echo 'DATABASE - ';
				$this->db = $arg;
				if ($this->super_debug) echo $this->db;
			}
			elseif (0 != preg_match('/^\\s*(SELECT|INSERT|UPDATE|DELETE|DROP|DESC|REPLACE|CREATE|ALTER|ANALYZE|BACKUP|CACHE|CHANGE|CHECK|COMMIT|DEALLOCATE|DO|EXECUTE|EXPLAIN|FLUSH|GRANT|HANDLER|HELP|KILL|LOAD|LOCK|MASTER|OPTIMIZE|PREPARE|PURGE|RENAME|REPAIR|RESET|RESTORE|REVOKE|ROLL|SAVE|SET|SHOW|START|STOP|TRUNCATE|UNLOCK|USE)/i', $arg)) // it begins with a query word
			{
				if ($this->super_debug) echo 'QUERY - ';
				$this->pass_query = $arg;
				if ($this->super_debug) echo $this->pass_query;
			}
			else
			{
				if ($this->super_debug) echo 'UNKNOWN - ';
				$arg_dump = var_export($arg, true);
				$this->error = 'Unknown argument found: ' . $arg_dump;
				if ($this->super_debug) echo $this->error;
			}
		}

		// wait until after all arguments are entered before outputting error
		// because the error may happen on the first argument and the other
		// arguments have important error report data (it's what they're for)
		if ('Unknown argument' == substr((string) $this->error, 0, 16))
		{
			$this->error_report( );
		}

		if ($this->super_debug) {echo'<pre>';print_r($this->get_arguments( ));echo'</pre>';}
	}



	/* clear the arguments */
	function clear_arguments( )
	{
		// don't clear query or db as we may use them later
		$this->line = false;
		$this->file_name = false;
		$this->error = false;
		$this->pass_query = false;
	}



	/* return the arguments */
	function get_arguments( )
	{
		$args['line'] = $this->line;
		$args['file'] = $this->file_name;
		$args['error'] = $this->error;
		$args['query'] = $this->pass_query;

		return $args;
	}

} // end of mysql class



/*
 +---------------------------------------------------------------------------
 |   > Extra SQL Functions
 +---------------------------------------------------------------------------
*/


/* escape the data before it gets queried into the database */
function sani($data)
{
	if (is_array($data))
	{
		return array_map('sani', $data);
	}
	else
	{
		if (get_magic_quotes_gpc( ))
		{
			$data = stripslashes($data);
		}

#    $data = htmlentities($data, ENT_NOQUOTES); // convert html to &html;

		if (function_exists('mysql_real_escape_string'))
		{
			$data = mysql_real_escape_string($data); // php 4.3.0+
		}
		else
		{
			$data = mysql_escape_string($data); // php 4.0+
		}

		return $data;
	}
}


if ( ! function_exists('microtime_float'))
{
	function microtime_float( )
	{
		list($usec, $sec) = explode(' ', microtime( ));
		return ((float)$usec + (float)$sec);
	}
}


function safe_var_export($var)
{
	if ( ! is_array($var))
	{
		return var_export($var, true);
	}

	foreach ($var as $key => $data)
	{
		if (('GLOBALS' == $key) || ($data == $var))
		{
			$var[$key] = 'RECURSION';
			continue;
		}
	}

	return var_export($var, true);
}

?>
0
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024
18 nov. 2015 à 10:31
Quelqu' un peut il me répondre?
0
jordane45 Messages postés 38254 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 octobre 2024 4 692
18 nov. 2015 à 10:57
Ce n'est pas le fichier de CONFIG qu'il faut modifier ... mais la CLASS.

Dans la CLASS sont utilisées des instructions mysql .... qu'il faut ocnvertir en mysqli
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024
Modifié par jordane45 le 20/11/2015 à 10:02
N'y a t-il pas d'erreur déjà pour ces deux fonctions?

function connect( )
 {
  $num_args = func_num_args( );
  $args     = func_get_args( );

  // get the arguments, if any
  if (0 != $num_args)
  {
   $this->load_arguments($args);
  }

  $this->linkid = @mysqli_connect($this->host, $this->user, $this->pswd);

  if ( ! $this->linkid)
  {
   $this->error = mysqli_errno( ).': '.mysqli_error( );
   $this->error_report( );

   if ($this->error_debug)
   {
    echo "There was an error connecting to the server in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
   }
   else
   {
    die('There was a database error. An email has been sent to the system administrator.');
   }
  }
 }



 /* Selects the MySQL Database */
 function select( )
 {
  $num_args = func_num_args( );
  $args     = func_get_args( );

  // get the arguments, if any
  if (0 != $num_args)
  {
   $this->load_arguments($args);
  }

  if ( ! @mysqli_select_db($this->db, $this->linkid))
  {
   $this->error = mysqli_errno($this->linkid).': '.mysql_error($this->linkid);
   $this->error_report( );

   if ($this->error_debug)
   {
    echo "There was an error selecting the database in {$this->file_name} on line {$this->line}:<br />ERROR - {$this->error}";
   }
   else
   {
    die('There was a database error. An email has been sent to the system administrator.');
   }
  }
 }



EDIT : Ajout du LANGAGE dans les balises de code (la coloration syntaxique).
Explications disponibles ici : ICI

Merci d'y penser dans tes prochains messages.
0