Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> PDO - problem z łączeniem z bazą danych...
Hubi.pl
post
Post #1





Grupa: Zarejestrowani
Postów: 73
Pomógł: 0
Dołączył: 16.10.2004
Skąd: Poznań

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


Witam,
postanowiłem sprawdzić ten dodatek w php5, a mianowicie PDO.
Na samym poczatku niestety napotkałem na błędy (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

przy takim kodzie pojawił mi się taki błąd:
  1. <?php
  2. $dbh = new PDO('mysql:dbname=php5;host=localhost', 'root', '');
  3. // let's have exceptions instead of silence.
  4. // other modes: PDO_ERRMODE_SILENT (default - check $stmt->errorCode() and $stmt->errorInfo())
  5. // PDO_ERRMODE_WARNING (php warnings)
  6. $dbh->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
  7. // one-shot query
  8. $dbh->exec("create table test(name varchar(255) not null primary key, value varchar(255));");
  9. ?> 

Cytat
Fatal error: Uncaught exception 'PDOException' with message '[2017] Can't open named pipe to host: . pipe: MySQL (2)' in F:\cms\php5\test.php:3 Stack trace: #0 F:\cms\php5\test.php(3): PDO->__construct('mysql:dbname=ph...', 'root', '') #1 {main} thrown in F:\cms\php5\test.php on line 3

natomiast przy takim:
  1. <?php
  2. try {
  3. $dbh = new PDO("mysql:php5", "root", "");
  4. print "Connectedn";
  5. } catch (Exception $e) {
  6. echo "Failed: " . $e->getMessage();
  7. }
  8. ?>

błąd był tego typu:
Cytat
Failed: [2017] Can't open named pipe to host: . pipe: MySQL (2)


Hm... co może być źle?
Po tych rodzajach błedów szukałem trochę i zauważyłem, że wiele osób ma podobne problemy.. lecz prawidłowego rozwiązania nie było (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

Macie jakieś pomysły?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
chmolu
post
Post #2





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 8.10.2004

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


Myślę, że problem raczej nie leży w samym PDO. Bardziej prawdopodobne jest złe ustawienie mySQLa. Napisz, jakiej wersji używasz.

Przeszperałem trochę google i znalazłem coś takiego (może się przyda):
Cytat
Can't open named pipe error
If you use a MySQL Version 3.22 server on NT with the newest MySQL client programs, you will get the following error:

error 2017: can't open named pipe to host: . pipe...
This is because the release version of MySQL uses named pipes on NT by default. You can avoid this error by using the --host=localhost option to the new MySQL clients or create an option file `C:\my.cnf' that contains the following information:

[client]
host = localhost
Starting from 3.23.50, named pipes are enabled only if mysqld-nt or mysqld-max-nt is started with --enable-named-pipe.
Go to the top of the page
+Quote Post
Hubi.pl
post
Post #3





Grupa: Zarejestrowani
Postów: 73
Pomógł: 0
Dołączył: 16.10.2004
Skąd: Poznań

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


serwer:
- Apache 2.0.52
- php 5.0.3
- MySQL 4.0.23

całość na Webserv i na XP

i przy Mysqld-Max-Nt ani Mysqld-Nt jest ten sam bład (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

Ten post edytował Hubi.pl 1.11.2005, 11:00:28
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Ja uzywam adresu "127.0.0.1" zamiast "localhost" i wtedy nie laczy sie przez "pipe" czy "unix socket" tylko przez TCP/IP (zawsze mialem problemy z ustawieniem tych gniazd (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif) ).
Go to the top of the page
+Quote Post
Hubi.pl
post
Post #5





Grupa: Zarejestrowani
Postów: 73
Pomógł: 0
Dołączył: 16.10.2004
Skąd: Poznań

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


dzięki dr_bonzo - zmieniłem na IP i działa (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)
doczytałem potem, że mozna jeszcze w c:\windows\hosts ustawić przekierowanie i też działa (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

pzdr.
EOT
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 24.08.2025 - 08:32