Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]This function is deprecated
Forum PHP.pl > Forum > Przedszkole
syreczq
Witam,
mam pewien problem z moim skryptem, mianowicie gdy uruchomiam go na localhoscie wyświetla sie:
Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in C:\WebServ\httpd\system\classes\mysql.php on line 188
Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in C:\WebServ\httpd\system\classes\mysql.php on line 188

Rozumiem z tego że funkcja: mysql_ecape_string() jest przestarzała. Próbowałem wyłączyć komunikaty, ale to nic nie dało. Zmieniałem też na mysql_real_escape_string(). Oto plik mysql.php:
  1. <?php
  2. if(!defined('MOZG'))
  3. die('Włamanie!');
  4.  
  5. class db{
  6.  
  7. var $db_id = false;
  8. var $query_num = 0;
  9. var $query_list = array();
  10. var $mysql_error = '';
  11. var $mysql_version = '';
  12. var $mysql_error_num = 0;
  13. var $mysql_extend = "MySQLi";
  14. var $MySQL_time_taken = 0;
  15. var $query_id = false;
  16.  
  17.  
  18. function connect($db_user, $db_pass, $db_name, $db_location = 'localhost', $show_error=1){
  19. $db_location = explode(":", $db_location);
  20.  
  21. if (isset($db_location[1])) {
  22.  
  23. $this->db_id = @mysqli_connect($db_location[0], $db_user, $db_pass, $db_name, $db_location[1]);
  24.  
  25. } else {
  26.  
  27. $this->db_id = @mysqli_connect($db_location[0], $db_user, $db_pass, $db_name);
  28.  
  29. }
  30.  
  31. if(!$this->db_id) {
  32. if($show_error == 1) {
  33. $this->display_error(mysqli_connect_error(), '1');
  34. } else {
  35. return false;
  36. }
  37. }
  38.  
  39. $this->mysql_version = mysqli_get_server_info($this->db_id);
  40.  
  41. if(!defined('COLLATE'))
  42. {
  43. define ("COLLATE", "cp1251");
  44. }
  45.  
  46. mysqli_query($this->db_id, "SET NAMES '" . COLLATE . "'");
  47.  
  48. return true;
  49. }
  50.  
  51. function query($query, $show_error=true){
  52. $time_before = $this->get_real_time();
  53.  
  54. if(!$this->db_id) $this->connect(DBUSER, DBPASS, DBNAME, DBHOST);
  55.  
  56. if(!($this->query_id = mysqli_query($this->db_id, $query) )) {
  57.  
  58. $this->mysql_error = mysqli_error($this->db_id);
  59. $this->mysql_error_num = mysqli_errno($this->db_id);
  60.  
  61. if($show_error) {
  62. $this->display_error($this->mysql_error, $this->mysql_error_num, $query);
  63. }
  64. }
  65.  
  66. $this->MySQL_time_taken += $this->get_real_time() - $time_before;
  67.  
  68. $this->query_num ++;
  69.  
  70. return $this->query_id;
  71. }
  72.  
  73. function get_row($query_id = ''){
  74. if ($query_id == '') $query_id = $this->query_id;
  75.  
  76. return mysqli_fetch_assoc($query_id);
  77. }
  78.  
  79. function get_array($query_id = ''){
  80. if ($query_id == '') $query_id = $this->query_id;
  81.  
  82. return mysqli_fetch_array($query_id);
  83. }
  84.  
  85. function super_query($query, $multi = false, $cache_prefix = false, $system_cache = false){
  86.  
  87. if($cache_prefix){
  88.  
  89. if($system_cache)
  90.  
  91. $data = system_cache($cache_prefix);
  92.  
  93. else
  94.  
  95. $data = mozg_cache($cache_prefix);
  96.  
  97. }
  98.  
  99. if($data){
  100.  
  101. $unSerData = unserialize($data);
  102.  
  103. if($unSerData)
  104.  
  105. return $unSerData;
  106.  
  107. else
  108.  
  109. return array();
  110.  
  111. } else {
  112.  
  113. if(!$multi) {
  114.  
  115. $this->query($query);
  116. $data = $this->get_row();
  117. $this->free();
  118.  
  119. if($cache_prefix){
  120.  
  121. $cache_rows = serialize($data);
  122.  
  123. mozg_create_cache($cache_prefix, $cache_rows);
  124.  
  125. }
  126.  
  127. return $data;
  128.  
  129. } else {
  130. $this->query($query);
  131.  
  132. $rows = array();
  133. while($row = $this->get_row()) {
  134. $rows[] = $row;
  135. }
  136.  
  137. $this->free();
  138.  
  139. if($cache_prefix){
  140.  
  141. $cache_rows = serialize($rows);
  142.  
  143. if($system_cache)
  144.  
  145. creat_system_cache($cache_prefix, $cache_rows);
  146.  
  147. else
  148.  
  149. mozg_create_cache($cache_prefix, $cache_rows);
  150. }
  151.  
  152. return $rows;
  153.  
  154. }
  155.  
  156. }
  157. }
  158.  
  159. function num_rows($query_id = ''){
  160. if ($query_id == '') $query_id = $this->query_id;
  161.  
  162. return mysqli_num_rows($query_id);
  163. }
  164.  
  165. function insert_id(){
  166. return mysqli_insert_id($this->db_id);
  167. }
  168.  
  169. function get_result_fields($query_id = '') {
  170. if ($query_id == '') $query_id = $this->query_id;
  171.  
  172. while ($field = mysqli_fetch_field($query_id))
  173. {
  174. $fields[] = $field;
  175. }
  176.  
  177. return $fields;
  178. }
  179.  
  180. function safesql( $source ){
  181. if ($this->db_id) return mysqli_real_escape_string ($this->db_id, $source);
  182. else return mysql_escape_string($source);
  183. }
  184.  
  185. function free( $query_id = '' ){
  186.  
  187. if ($query_id == '') $query_id = $this->query_id;
  188.  
  189. @mysqli_free_result($query_id);
  190. }
  191.  
  192. function close(){
  193. @mysqli_close($this->db_id);
  194. }
  195.  
  196. function get_real_time(){
  197. list($seconds, $microSeconds) = explode(' ', microtime());
  198. return ((float)$seconds + (float)$microSeconds);
  199. }
  200.  
  201. function display_error($error, $error_num, $query = ''){
  202. if($query) {
  203. $query = preg_replace("/([0-9a-f]){32}/", "********************************", $query);
  204. $query_str = "$query";
  205. }
  206.  
  207. echo '<?xml version="1.0" encoding="iso-8859-1"?>
  208. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  209. <html xmlns="http://www.w3.org/1999/xhtml">
  210. <head>
  211. <title>Błąd!</title>
  212. <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
  213. </head>
  214. <body>
  215. <font size="4">Błąd serwera, spróbuj odświeżyć stronę później.</font>
  216. </body>
  217. </html>';
  218.  
  219. exit();
  220. }
  221.  
  222. }
  223. ?>

Prosiłbym o pomoc z tym jak się pozbyć tego komunikatu i by wszystko działało, z góry dziękuje za odpowiedzi. Nie proszę o gotowca poprawionego pliku: mysql.php(chociaż nie będe miał nic przeciwko smile.gif )tylko o pomoc. Pozdrawiam
fate
use mysql_real_escape_string() instead. in C:\WebServ\httpd\system\classes\mysql.php on line 188
wrzuc do translatora
syreczq
Umiem angielski snitch.gif próbowałem użyć mysql_real_escape_string() zamiast mysql_escape_string() ale dalej pojawiał się komunikat.
fastlone
Widocznie nie zmieniłeś jej we wszystkich miejscach.
syreczq
Zamiast mysql_escape_string() wpisałem mysql_real_escape_string () tak to wyglądało:
  1. function safesql( $source ){
  2. if ($this->db_id) return mysqli_real_escape_string ($this->db_id, $source);
  3. else return mysql_real_escape_string($source);
  4. }

Więc chyba dobrze powinno być, jeśli nie to proszę wyjaśnić zielony jestem.
fate
Ktora masz wersje PHP?
Ogolnie w uzyciu jest teraz PDO i mysqli

Po zamianie pojawia sie inny komunikat, nie doczytales i myslales ze ten sam
syreczq
Mam php 5.4.1. Zmieniłem i teraz wyświetla tylko:  Błąd serwera, spróbuj odświeżyć stronę później.
Ale jak odświeżę kilka razy stronę to znowu pojawia się:
Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in C:\WebServ\httpd\system\classes\mysql.php on line 188
Rysh
Dlaczego używasz raz mysql_ a raz mysqli_ ?
Pozatym dlaczego mutujesz błędy które zwracają Ci funkcje?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.