Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP][PHP/SQL] Use mysqli or PDO
Forum PHP.pl > Forum > Przedszkole
123KOMORNIK321
Cześć, z góry muszę wam powiedzieć że jeszcze nie potrafię pisać w php
Mam taki kod od znaj i spytał się czy mogę mu go przepisać aby nie wyświetlał się błąd

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO

To jest kod

  1. $root = (empty($_SERVER['DOCUMENT_ROOT']) ? getenv("DOCUMENT_ROOT") : $_SERVER['DOCUMENT_ROOT']);
  2. require_once $root.'/config.inc.php';
  3. class Database {
  4.  
  5. var $server = "localhost"; //database server
  6. var $user = "root"; //database login name
  7. var $pass = ""; //database login password
  8. var $database = ""; //database name
  9. var $pre = ""; //table prefix
  10. var $showerror = false;
  11. #######################
  12. //internal info
  13. var $error = "";
  14. var $errno = 0;
  15. //number of rows affected by SQL query
  16. var $affected_rows = 0;
  17. var $link_id = 0;
  18. var $query_id = 0;
  19.  
  20. #-#############################################
  21. # desc: constructor
  22.  
  23. function Database($database) {
  24. $root = (empty($_SERVER['DOCUMENT_ROOT']) ? getenv("DOCUMENT_ROOT") : $_SERVER['DOCUMENT_ROOT']);
  25. require_once $root.'/config.inc.php';
  26. if (isset($database) && ($database == "FORUMS")) {
  27. $this->server = DB_FORUMS_SERVER;
  28. $this->user = DB_FORUMS_USER;
  29. $this->pass = DB_FORUMS_PASS;
  30. $this->database = DB_FORUMS_DATABASE;
  31. $this->pre = DB_FORUMS_PREFIX;
  32. } elseif (isset($database) && $database == "LOGS") {
  33. $this->server = DB_LOGS_SERVER;
  34. $this->user = DB_LOGS_USER;
  35. $this->pass = DB_LOGS_PASS;
  36. $this->database = DB_LOGS_DATABASE;
  37. $this->pre = DB_LOGS_PREFIX;
  38. } elseif (isset($database) && $database == "MTA") {
  39. $this->server = DB_SERVER;
  40. $this->user = DB_USER;
  41. $this->pass = DB_PASS;
  42. $this->database = DB_DATABASE;
  43. $this->pre = DB_PREFIX;
  44. }
  45. $this->showerror = DB_SHOW_ERROR;
  46. }
  47.  
  48. #-#constructor()
  49. #-#############################################
  50. # desc: connect and select database using vars above
  51. # Param: $new_link can force connect() to open a new link, even if mysql_connect() was called before with the same parameters
  52.  
  53. function affected_rows() {
  54. return $this->affected_rows;
  55. }



  1. function connect($new_link = false) {
  2. // var_dump($this->server);die;
  3. $this->link_id = mysql_connect($this->server, $this->user, $this->pass, $new_link);
  4.  
  5. if (!$this->link_id) {//open failed
  6. $this->oops("Could not connect to server: <b>$this->server</b>.");
  7. }
  8.  
  9. if (!@mysql_select_db($this->database, $this->link_id)) {//no database
  10. $this->oops("Could not open database: <b>$this->database</b>.");
  11. }
  12.  
  13. // Deprecated but will get us rolling with mysql 5.7 for now.
  14.  
  15. $this->query("SET SESSION sql_mode = ''");
  16.  
  17. // unset the data so it can't be dumped
  18. $this->server = 'localhost - host name';
  19. $this->user = 'root - user name';
  20. $this->pass = 'pass';
  21. $this->database = 'db - name';
  22. }


Czytałem trochę o mysqli i PDO ale nie jestem w stanie mu tego zrobić i mam prośbę do was
Czy ktoś z was może mi to przepisać ?

PS: Jeśli chodzi o przepisywanie takiego kodu na przyszłość stosować PDO czy mysqli questionmark.gif
viking
Dział zleceń jest niżej.
vokiel
PDO to wrapper na wiele różnych baz, mysqli to tylko do MySQL/MariaDB.
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.