Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL] Problem z połączeniem
mateofi
post
Post #1





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 30.12.2004

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


Witam,

Mam problem przy łączeniu z bazą danych. Wyskakują mi następujące błędy:

  1. <?php
  2. Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in /home.7/m/a/t/mateofi/www/id/index.php on line 5
  3.  
  4. Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home.7/m/a/t/mateofi/www/id/index.php on line 6
  5.  
  6. Warning: mysql_select_db(): A link to the server could not be established in /home.7/m/a/t/mateofi/www/id/index.php on line 6
  7. ?>


Nie wiem w czym problem. Podaje 10 pierwszych lini skryptu:



  1. <?php
  2. $host="mysql.yoyo.pl";
  3. $baza = "mateofi";
  4. $pass ="dobrehaslo";
  5. $id_con = mysql_connect($host,$baza,$pass);
  6. mysql_select_db($baza) or die("Nie moge zaznaczyc bazy danych");
  7. $zapytanie = "SELECT COUNT(*) FROM news";
  8. $idzap2 = mysql_query($zapytanie) or die("Błąd zapytania.");
  9. ?>


Mam konto 1000 GP na ovh.org, lecz kożystam z bazy danych na yoyo.pl.

Kożystając z 60free na ovh.org i lokalnej bazie danych nie było problemów.

Zrobiłem coś takiego:

  1. SET PASSWORD FOR mateofi@localhost = OLD_PASSWORD('dobrehaslo')


ale nic nie dało.

Wersja MySQL to: 5.0.22-Debian_3

Pozdrowienia
mateofi
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #2





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Spróbuj przez mysqli_connect() lub użyj PDO.

Pozdrawiam.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
mateofi
post
Post #3





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 30.12.2004

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


ja myślę, że można normalnie się łączyć z serwerem, tylko nowe bazy danych są jakieś inne i trzeba coś w nich ustawić, ale ja nie wiem co.
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #4





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Fakt., jest jakaś mozliwośc w Mysql5 na stosowanie starego typu autentyfikacji, ale lepiej użyj PDO. To teraz jest/będzie standard i warto sie nauczyć,

Pozdrawiam.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
mateofi
post
Post #5





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 30.12.2004

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


a do pdo potrzebna mi jest jakaś klasa na dysku??
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #6





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




W php5 automatycznie jest instalowane PDO, lecz aby uzywać z mysql, musisz przy robienie ./configure podać sterowniki do mysql i innych baz (o ile używasz).
Nie wiem jak jest pod windowsem, bo nie instalowałem.

Reszte znajdziesz w manualu.

Pozdrawiam.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
mateofi
post
Post #7





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 30.12.2004

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


nie mogę sobie poradzić z tym pdo. sad.gif

Proszę o pomoc w połączeniu przez zwykły kod, nie obiektowo.

bardzo proszę.
Go to the top of the page
+Quote Post
nazihipi
post
Post #8





Grupa: Zarejestrowani
Postów: 139
Pomógł: 0
Dołączył: 14.07.2006

Ostrzeżenie: (10%)
X----


  1. <?php
  2. class Database {
  3. // Prywatne skladowe klasy
  4. private $_mDb;
  5.  
  6. /**
  7.    * Konstruktor klasy. Utworz nowe polaczenie
  8.    * 
  9.    * @access public
  10.    * @param string $db_connection_string
  11.    * @param string $db_user
  12.    * @param string $db_password
  13.    * @param string $db_persistent
  14.    */
  15. function __construct( $db_connection_string, $db_user, $db_password, $db_persistent ) {
  16. try {
  17. $this->_mDb = new PDO( $db_connection_string, $db_user, 
  18. $db_password, array( PDO::ATTR_PERSISTENT => $db_persistent ) );
  19. $this->_mDb->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  20. $this->_mDb->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true );
  21. }
  22. catch ( Exception $e ) {
  23. if( DEBBUGING ) {
  24. echo 'Error: ' . $e->getMessage();
  25. }
  26. else {
  27. echo 'Zapraszamy pozniej.';
  28. }
  29. }
  30. }
  31. // metody dla zapytan.....
  32. //
  33. //
  34. //
  35. }
  36. ?>

przykładowe wywołanie:
  1. <?php
  2. define( 'DEBBUGING', true );
  3.  
  4. $dbHandler = new Database( 'mysql:host=localhost;dbname=data', 'root', 'pass', true );
  5. ?>


możesz sobie przmielić do proceduralnego jak nie chcesz w klasie

Ten post edytował nazihipi 20.08.2006, 16:47:53
Go to the top of the page
+Quote Post
mateofi
post
Post #9





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 30.12.2004

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


dzięki wielkie. zaraz popróbuje smile.gif
Go to the top of the page
+Quote Post
SongoQ
post
Post #10





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

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


@mateofi Jest takie cos jak manual sa tam przyklady sprawdzone i na ktorych trzeba sie wzorowac.
http://pl.php.net/manual/en/ref.pdo.php


--------------------
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 Aktualny czas: 22.08.2025 - 01:05