Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Naprawa przestarzałych funkcji i metod w pliku PHP
NeXt2k20
post 16.02.2020, 14:53:07
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 16.02.2020

Ostrzeżenie: (0%)
-----


Witam,
Posiadam w plikach przestarzałe funkcję i nie jestem w stanie tego ogarnąć, jest ktoś w stanie pomóc? Tu jest jeden z plików:
Mam wersję PHP 5.6
Szukam pilnie odpłatnej pomocy. Kontakt pw, albo discord: NeXt#3957

  1. <?php
  2.  
  3. /*
  4.  * To change this license header, choose License Headers in Project Properties.
  5.  * To change this template file, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9.  
  10. /**
  11.  * Description of session
  12.  *
  13.  * @author Maxime
  14.  */
  15.  
  16.  
  17.  
  18. require_once("config.inc.php");
  19.  
  20. //$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
  21. ################################################################################
    ###################
  22. ################################################################################
    ###################
  23. ################################################################################
    ###################
  24. class Database {
  25. var $server = ""; //database server
  26. var $user = ""; //database login name
  27. var $pass = ""; //database login password
  28. var $database = ""; //database name
  29. var $pre = ""; //table prefix
  30. #######################
  31. //internal info
  32. var $error = "";
  33. var $errno = 0;
  34. //number of rows affected by SQL query
  35. var $affected_rows = 0;
  36. var $link_id = 0;
  37. var $query_id = 0;
  38.  
  39. #-#############################################
  40. # desc: constructor
  41.  
  42. function Database($database) {
  43. if (isset($database) && ($database == "FORUMS")) {
  44. $this->server = DB_FORUMS_SERVER;
  45. $this->user = DB_FORUMS_USER;
  46. $this->pass = DB_FORUMS_PASS;
  47. $this->database = DB_FORUMS_DATABASE;
  48. } elseif (isset($database) && $database == "LOGS") {
  49. $this->server = DB_LOGS_SERVER;
  50. $this->user = DB_LOGS_USER;
  51. $this->pass = DB_LOGS_PASS;
  52. $this->database = DB_LOGS_DATABASE;
  53. } elseif (isset($database) && $database == "MTA") {
  54. $this->server = DB_SERVER;
  55. $this->user = DB_USER;
  56. $this->pass = DB_PASS;
  57. $this->database = DB_DATABASE;
  58. }
  59. }
  60.  
  61. #-#constructor()
  62. #-#############################################
  63. # desc: connect and select database using vars above
  64. # Param: $new_link can force connect() to open a new link, even if mysql_connect() was called before with the same parameters
  65.  
  66. function affected_rows(){
  67. return $this->affected_rows;
  68. }
  69.  
  70. function connect($new_link = false) {
  71. $this->link_id = mysql_connect($this->server, $this->user, $this->pass, $new_link);
  72.  
  73. if (!$this->link_id) {//open failed
  74. $this->oops("Could not connect to server: <b>$this->server</b>.");
  75. }
  76.  
  77. if (!@mysql_select_db($this->database, $this->link_id)) {//no database
  78. $this->oops("Could not open database: <b>$this->database</b>.");
  79. }
  80.  
  81. // unset the data so it can't be dumped
  82. $this->server = '';
  83. $this->user = '';
  84. $this->pass = '';
  85. $this->database = '';
  86. }
  87.  
  88. #-#connect()
  89. #-#############################################
  90. # desc: close the connection
  91.  
  92. function close() {
  93. if (!@mysql_close($this->link_id)) {
  94. $this->oops("Connection close failed.");
  95. }
  96. }
  97.  
  98. #-#close()
  99. #-#############################################
  100. # Desc: escapes characters to be mysql ready
  101. # Param: string
  102. # returns: string
  103.  
  104. function escape($string) {
  105. $string = stripslashes($string);
  106. return @mysql_real_escape_string($string, $this->link_id);
  107. }
  108.  
  109. #-#escape()
  110. #-#############################################
  111. # Desc: executes SQL query to an open connection
  112. # Param: (MySQL query) to execute
  113. # returns: (query_id) for fetching results etc
  114.  
  115. function query($sql) {
  116. // do query
  117. $this->query_id = @mysql_query($sql, $this->link_id);
  118.  
  119. if (!$this->query_id) {
  120. $this->oops("<b>MySQL Query fail:</b> $sql");
  121. return 0;
  122. }
  123.  
  124. $this->affected_rows = mysql_affected_rows($this->link_id);
  125.  
  126. return $this->query_id;
  127. }
  128.  
  129. #-#query()
  130. #-#############################################
  131. # desc: fetches and returns results one line at a time
  132. # param: query_id for mysql run. if none specified, last used
  133. # return: (array) fetched record(s)
  134.  
  135. function fetch_array($query_id = -1) {
  136. // retrieve row
  137. if ($query_id != -1) {
  138. $this->query_id = $query_id;
  139. }
  140.  
  141. if (isset($this->query_id)) {
  142. $record = @mysql_fetch_assoc($this->query_id);
  143. } else {
  144. $this->oops("Invalid query_id: <b>$this->query_id</b>. Records could not be fetched.");
  145. }
  146.  
  147. return $record;
  148. }
  149.  
  150. #-#fetch_array()
  151. #-#############################################
  152. # desc: returns all the results (not one row)
  153. # param: (MySQL query) the query to run on server
  154. # returns: assoc array of ALL fetched results
  155.  
  156. function fetch_all_array($sql) {
  157. $query_id = $this->query($sql);
  158. $out = array();
  159.  
  160. while ($row = $this->fetch_array($query_id)) {
  161. $out[] = $row;
  162. }
  163.  
  164. $this->free_result($query_id);
  165. return $out;
  166. }
  167.  
  168. #-#fetch_all_array()
  169. #-#############################################
  170. # desc: frees the resultset
  171. # param: query_id for mysql run. if none specified, last used
  172.  
  173. function free_result($query_id = -1) {
  174. if ($query_id != -1) {
  175. $this->query_id = $query_id;
  176. }
  177. if ($this->query_id != 0 && !@mysql_free_result($this->query_id)) {
  178. $this->oops("Result ID: <b>$this->query_id</b> could not be freed.");
  179. }
  180. }
  181.  
  182. #-#free_result()
  183. #-#############################################
  184. # desc: does a query, fetches the first row only, frees resultset
  185. # param: (MySQL query) the query to run on server
  186. # returns: array of fetched results
  187.  
  188. function query_first($query_string) {
  189. $query_id = $this->query($query_string);
  190. $out = $this->fetch_array($query_id);
  191. $this->free_result($query_id);
  192. return $out;
  193. }
  194.  
  195. #-#query_first()
  196. #-#############################################
  197. # desc: does an update query with an array
  198. # param: table (no prefix), assoc array with data (doesn't need escaped), where condition
  199. # returns: (query_id) for fetching results etc
  200.  
  201. function query_update($table, $data, $where = '1') {
  202. $q = "UPDATE `" . $this->pre . $table . "` SET ";
  203.  
  204. foreach ($data as $key => $val) {
  205. if (strtolower($val) == 'null')
  206. $q.= "`$key` = NULL, ";
  207. elseif (strtolower($val) == 'now()')
  208. $q.= "`$key` = NOW(), ";
  209. elseif (preg_match("/^increment\((\-?\d+)\)$/i", $val, $m))
  210. $q.= "`$key` = `$key` + $m[1], ";
  211. else
  212. $q.= "`$key`='" . $this->escape($val) . "', ";
  213. }
  214.  
  215. $q = rtrim($q, ', ') . ' WHERE ' . $where . ';';
  216.  
  217. return $this->query($q);
  218. }
  219.  
  220. #-#query_update()
  221. #-#############################################
  222. # desc: does an insert query with an array
  223. # param: table (no prefix), assoc array with data
  224. # returns: id of inserted record, false if error
  225.  
  226. function query_insert($table, $data) {
  227. $q = "INSERT INTO `" . $this->pre . $table . "` ";
  228. $v = '';
  229. $n = '';
  230.  
  231. foreach ($data as $key => $val) {
  232. $n.="`$key`, ";
  233. if (strtolower($val) == 'null')
  234. $v.="NULL, ";
  235. elseif (strtolower($val) == 'now()')
  236. $v.="NOW(), ";
  237. else
  238. $v.= "'" . $this->escape($val) . "', ";
  239. }
  240.  
  241. $q .= "(" . rtrim($n, ', ') . ") VALUES (" . rtrim($v, ', ') . ");";
  242.  
  243. if ($this->query($q)) {
  244. //$this->free_result();
  245. return mysql_insert_id($this->link_id);
  246. } else
  247. return false;
  248. }
  249.  
  250. #-#query_insert()
  251. #-#############################################
  252. # desc: throw an error message
  253. # param: [optional] any custom error to display
  254.  
  255. function oops($msg = '') {
  256. if ($this->link_id > 0 and $this->link_id != 5) {
  257. $this->error = mysql_error($this->link_id);
  258. $this->errno = mysql_errno($this->link_id);
  259. } else {
  260. $this->error = mysql_error();
  261. $this->errno = mysql_errno();
  262. }
  263. ?>
  264. <table align="center" border="1" cellspacing="0" style="background:white;color:black;width:80%;">
  265. <tr><th colspan=2>Database Error</th></tr>
  266. <tr><td align="right" valign="top">Message:</td><td><?php echo $msg; ?></td></tr>
  267. <?php if (!empty($this->error)) echo '<tr><td align="right" valign="top" nowrap>MySQL Error:</td><td>' . $this->error . '</td></tr>'; ?>
  268. <tr><td align="right">Date:</td><td><?php echo date("l, F j, Y \a\\t g:i:s A"); ?></td></tr>
  269. <?php if (!empty($_SERVER['REQUEST_URI'])) echo '<tr><td align="right">Script:</td><td><a href="' . $_SERVER['REQUEST_URI'] . '">' . $_SERVER['REQUEST_URI'] . '</a></td></tr>'; ?>
  270. <?php if (!empty($_SERVER['HTTP_REFERER'])) echo '<tr><td align="right">Referer:</td><td><a href="' . $_SERVER['HTTP_REFERER'] . '">' . $_SERVER['HTTP_REFERER'] . '</a></td></tr>'; ?>
  271. </table>
  272. <?php
  273. }
  274.  
  275. #-#oops()
  276. }
  277.  
  278. //CLASS Database
  279. ################################################################################
    ###################
  280. ?>




Ten post edytował NeXt2k20 16.02.2020, 14:54:14
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 21:00