Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem z połączeniem DB
123KOMORNIK321
post 5.03.2021, 22:11:09
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 1.03.2021

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


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.
Go to the top of the page
+Quote Post
viking
post 6.03.2021, 09:04:08
Post #2





Grupa: Zarejestrowani
Postów: 6 377
Pomógł: 1116
Dołączył: 30.08.2006

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


Zajrzaleś do dokumentacji? 4 parametr to baza a nie boolean który przekazujesz. I to pokazuje że linia 9 nie ma też sensu.


--------------------
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: 12.06.2025 - 11:43