Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Problem z połączeniem DB
Forum PHP.pl > Forum > Przedszkole
123KOMORNIK321
Cześć, trochę czytam na temat PDO i mysqli i udało mi się przepisać kod i już nie sypią się błędy ale mam problem z połączeniem DB

Tu jest kod:

  1. function connect($new_link = false) {
  2. // var_dump($this->server);die;
  3. $this->link_id = mysqli_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 (!@mysqli_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'; // Tutaj podaje host name
  19. $this->user = 'root'; // Tutaj podaje user name
  20. $this->pass = ' '; // Tutaj podaje hasło
  21. $this->database = ''; //Tutaj podaje db name
  22. }


Otrzymuje taki błąd

Warning: mysqli_connect(): (HY000/1049): Unknown database '1' in C:\xampp\htdocs\classes\Database.class.php on line 74

Dane do DB są na 100% poprawne i nie rozumiem skąd bierze się baza o nazwie '1'

Linia 74:

  1. $this->link_id = mysqli_connect($this->server, $this->user, $this->pass, $new_link);


Z góry dziękuje za pomoc.
viking
Zajrzaleś do dokumentacji? 4 parametr to baza a nie boolean który przekazujesz. I to pokazuje że linia 9 nie ma też sensu.
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.