From 630efbdeb9da761537971ee9021471cc0e25da70 Mon Sep 17 00:00:00 2001 From: Sit Melai Date: Wed, 11 Jan 2017 20:44:44 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20regexp=20pour=20se?= =?UTF-8?q?=20connecter=20=C3=A0=20une=20base=20mysql=20depuis=20un=20stri?= =?UTF-8?q?ng.=20Il=20y=20avait=20le=20bon=20regexp=20dans=20le=20function?= =?UTF-8?q?s=5Fmysql.php=20mais=20pas=20dans=20le=20functions=5Fmysqli.php?= =?UTF-8?q?=20(et=20c'est=20meilleur=20d'utiliser=20mysqli=20car=20mysql?= =?UTF-8?q?=20est=20d=C3=A9pr=C3=A9ci=C3=A9=20dans=20les=20php=20r=C3=A9ce?= =?UTF-8?q?nt/m=C3=AAme=20plus=20inclus)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/public_php/admin/functions_mysqli.php | 591 +++++++++--------- 1 file changed, 296 insertions(+), 295 deletions(-) diff --git a/code/web/public_php/admin/functions_mysqli.php b/code/web/public_php/admin/functions_mysqli.php index 8cc2737c3..e7de5fb56 100755 --- a/code/web/public_php/admin/functions_mysqli.php +++ b/code/web/public_php/admin/functions_mysqli.php @@ -1,295 +1,296 @@ -persistency = $persistency; - $this->user = $sqluser; - $this->password = $sqlpassword; - $this->server = $sqlserver; - $this->dbname = $database; - - if($this->persistency) - { - $this->server = 'p:'.$this->server; - } - - $this->db_connect_id = mysqli_connect($this->server, $this->user, $this->password); - if($this->db_connect_id) - { - if($database != "") - { - $this->dbname = $database; - $dbselect = mysqli_select_db($this->db_connect_id, $this->dbname); - if(!$dbselect) - { - mysqli_close($this->db_connect_id); - $this->db_connect_id = $dbselect; - } - } - return $this->db_connect_id; - } - else - { - echo "Connection to mySQL failed!"; - exit; - } - } - - // - // Other base methods - // - function sql_close() - { - if($this->db_connect_id) - { - if($this->query_result) - { - @mysqli_free_result($this->query_result); - } - $result = mysqli_close($this->db_connect_id); - return $result; - } - else - { - return false; - } - } - - // - // Base query method - // - function sql_query($query = "", $transaction = FALSE) - { - // Remove any pre-existing queries - unset($this->query_result); - if($query != "") - { - nt_common_add_debug($query); - $this->num_queries++; - $this->query_result = mysqli_query($this->db_connect_id, $query); - } - if($this->query_result) - { - return $this->query_result; - } - else - { - return ( $transaction == 'END_TRANSACTION' ) ? true : false; - } - } - - function sql_select_db($dbname) - { - if($this->db_connect_id) - { - $result = mysqli_select_db($this->db_connect_id, $dbname); - return $result; - } - return false; - } - function sql_reselect_db() - { - if($this->db_connect_id) - { - $result = mysqli_select_db($this->db_connect_id, $this->dbname); - return $result; - } - return false; - } - // - // Other query methods - // - function sql_numrows($query_id = 0) - { - if(!$query_id) - { - $query_id = $this->query_result; - } - if($query_id) - { - $result = mysqli_num_rows($query_id); - return $result; - } - else - { - return false; - } - } - function sql_affectedrows() - { - if($this->db_connect_id) - { - $result = mysqli_affected_rows($this->db_connect_id); - return $result; - } - else - { - return false; - } - } - function sql_numfields($query_id = 0) - { - if(!$query_id) - { - $query_id = $this->query_result; - } - if($query_id) - { - $result = mysqli_num_fields($query_id); - return $result; - } - else - { - return false; - } - } - // function sql_fieldname($query_id = 0){} - // function sql_fieldtype($offset, $query_id = 0){} - function sql_fetchrow($query_id = 0) - { - if(!$query_id) - { - $query_id = $this->query_result; - } - if($query_id) - { - return mysqli_fetch_array($query_id); - } - else - { - return false; - } - } - function sql_fetchrowset($query_id = 0) - { - if(!$query_id) - { - $query_id = $this->query_result; - } - if($query_id) - { - while($row = mysqli_fetch_array($query_id)) - { - $result[] = $row; - } - return $result; - } - else - { - return false; - } - } - // function sql_fetchfield($field, $rownum = -1, $query_id = 0){} - // function sql_rowseek($rownum, $query_id = 0){} - function sql_nextid(){ - if($this->db_connect_id) - { - $result = mysqli_insert_id($this->db_connect_id); - return $result; - } - else - { - return false; - } - } - function sql_freeresult($query_id = 0){ - if(!$query_id) - { - $query_id = $this->query_result; - } - - if ( $query_id ) - { - @mysqli_free_result($query_id); - - return true; - } - else - { - return false; - } - } - function sql_escape_string($str) - { - return mysqli_real_escape_string($this->db_connect_id, $str); - } - function sql_error($query_id = 0) - { - $result["message"] = mysqli_error($this->db_connect_id); - $result["code"] = mysqli_errno($this->db_connect_id); - - return $result; - } - -} // class sql_db - -class sql_db_string extends sql_db -{ - // - // Constructor ($connstring format : mysql://user:password@host/dbname) - // - function sql_db_string($connstring, $persistency = true) - { - $ret = false; - if ($connstring != '') - { - if (preg_match("#^mysqli?://([^:]+)(?::([^@]*))?@([^\\/]+)/([^/]+)[/]?$#", $connstring, $params)) - { - $sqlserver = $params[3]; - $sqluser = $params[1]; - $sqlpassword = $params[2]; - $database = $params[4]; - - $ret = $this->sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency); - } - } - - return $ret; - } -} // class sql_db_string - - -} // if ... define - +persistency = $persistency; + $this->user = $sqluser; + $this->password = $sqlpassword; + $this->server = $sqlserver; + $this->dbname = $database; + + if($this->persistency) + { + $this->server = 'p:'.$this->server; + } + + $this->db_connect_id = mysqli_connect($this->server, $this->user, $this->password); + if($this->db_connect_id) + { + if($database != "") + { + $this->dbname = $database; + $dbselect = mysqli_select_db($this->db_connect_id, $this->dbname); + if(!$dbselect) + { + mysqli_close($this->db_connect_id); + $this->db_connect_id = $dbselect; + } + } + return $this->db_connect_id; + } + else + { + echo "Connection to mySQL failed!"; + exit; + } + } + + // + // Other base methods + // + function sql_close() + { + if($this->db_connect_id) + { + if($this->query_result) + { + @mysqli_free_result($this->query_result); + } + $result = mysqli_close($this->db_connect_id); + return $result; + } + else + { + return false; + } + } + + // + // Base query method + // + function sql_query($query = "", $transaction = FALSE) + { + // Remove any pre-existing queries + unset($this->query_result); + if($query != "") + { + nt_common_add_debug($query); + $this->num_queries++; + $this->query_result = mysqli_query($this->db_connect_id, $query); + } + if($this->query_result) + { + return $this->query_result; + } + else + { + return ( $transaction == 'END_TRANSACTION' ) ? true : false; + } + } + + function sql_select_db($dbname) + { + if($this->db_connect_id) + { + $result = mysqli_select_db($this->db_connect_id, $dbname); + return $result; + } + return false; + } + function sql_reselect_db() + { + if($this->db_connect_id) + { + $result = mysqli_select_db($this->db_connect_id, $this->dbname); + return $result; + } + return false; + } + // + // Other query methods + // + function sql_numrows($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = mysqli_num_rows($query_id); + return $result; + } + else + { + return false; + } + } + function sql_affectedrows() + { + if($this->db_connect_id) + { + $result = mysqli_affected_rows($this->db_connect_id); + return $result; + } + else + { + return false; + } + } + function sql_numfields($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + $result = mysqli_num_fields($query_id); + return $result; + } + else + { + return false; + } + } + // function sql_fieldname($query_id = 0){} + // function sql_fieldtype($offset, $query_id = 0){} + function sql_fetchrow($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + return mysqli_fetch_array($query_id); + } + else + { + return false; + } + } + function sql_fetchrowset($query_id = 0) + { + if(!$query_id) + { + $query_id = $this->query_result; + } + if($query_id) + { + while($row = mysqli_fetch_array($query_id)) + { + $result[] = $row; + } + return $result; + } + else + { + return false; + } + } + // function sql_fetchfield($field, $rownum = -1, $query_id = 0){} + // function sql_rowseek($rownum, $query_id = 0){} + function sql_nextid(){ + if($this->db_connect_id) + { + $result = mysqli_insert_id($this->db_connect_id); + return $result; + } + else + { + return false; + } + } + function sql_freeresult($query_id = 0){ + if(!$query_id) + { + $query_id = $this->query_result; + } + + if ( $query_id ) + { + @mysqli_free_result($query_id); + + return true; + } + else + { + return false; + } + } + function sql_escape_string($str) + { + return mysqli_real_escape_string($this->db_connect_id, $str); + } + function sql_error($query_id = 0) + { + $result["message"] = mysqli_error($this->db_connect_id); + $result["code"] = mysqli_errno($this->db_connect_id); + + return $result; + } + +} // class sql_db + +class sql_db_string extends sql_db +{ + // + // Constructor ($connstring format : mysql://user:password@host/dbname) + // + function sql_db_string($connstring, $persistency = true) + { + $ret = false; + if ($connstring != '') + { + //if (preg_match("#^mysqli?://([^:]+)(?::([^@]*))?@([^\\/]+)/([^/]+)[/]?$#", $connstring, $params)) + if (ereg("^mysql\:\/\/([^\:]+)\:([^\@]+)\@([^\\]+)\/([^\/]+)[\/]?$", $connstring, $params)) + { + $sqlserver = $params[3]; + $sqluser = $params[1]; + $sqlpassword = $params[2]; + $database = $params[4]; + + $ret = $this->sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency); + } + } + + return $ret; + } +} // class sql_db_string + + +} // if ... define +