Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Połaczenie z Baza danych
mk83
post 18.08.2005, 16:38:51
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 17.02.2005

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


Mam dosyc dziwny problem z nawiazaniem polaczenia z baza danych:

  1. <?php
  2.  
  3. require_once('DB-1.7.6/DB.php');
  4. $user='root';
  5. $password='krasnal';
  6. $host='localhost';
  7. $db_name='test';
  8.  
  9. print("Tekst testowy nr 1");
  10.  
  11. $dns="mysql://$user:$password@tcp($host)/$db_name";
  12. if (DB::isError($db=DB::connect($dns))) {
  13. die("Error!!!");
  14. } else { echo 'Połączenie nawiazane!!'; }
  15.  
  16. print("Tekst testowy nr 2");
  17.  
  18.  
  19. ?>


Nie dostaje rzadnego bledu. Co ciekawe w przgladarce pokazuje sie tylko napis Tekst testowy nr 1, i nic wiecej, nawet co mnie bardzo dziwi nie pokazuje sie
Tekst testowy nr 2. Prosze o pomoc bo pewnie znow strzeliłem jakis banalny bład i nie moge sie go doszukac.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mk83
post 19.08.2005, 20:55:22
Post #2





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 17.02.2005

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


Sprawdziłem ze problem powoduje metoda DB:conncet(), DB:isError() jest ok.
Pokazywanie błędów mam włączone. Jesli widzisz bład składni to powiedz w ktorym miejscu.
Co do var_dump() to sprawdzeniu metody connect otzymuje:

Przy wpisaniu var_dump(DB::connect())

Kod
Warning: Missing argument 1 for connect() in c:\usr\krasnal\www\sonda\Core\DB-1.7.6\DB.php on line 518
object(db_error)(8) { ["error_message_prefix"]=> string(0) "" ["mode"]=> int(1) ["level"]=> int(1024) ["code"]=> int(-4) ["message"]=> string(19) "DB Error: not found" ["userinfo"]=> string(41) "Unable to include the DB/.php file for ''" ["backtrace"]=> array(4) { [0]=> array(6) { ["file"]=> string(45) "c:\usr\krasnal\www\sonda\Core\DB-1.7.6\DB.php" ["line"]=> int(888) ["function"]=> string(10) "pear_error" ["class"]=> string(8) "db_error" ["type"]=> string(2) "->" ["args"]=> array(5) { [0]=> string(19) "DB Error: not found" [1]=> int(-4) [2]=> int(1) [3]=> int(1024) [4]=> string(41) "Unable to include the DB/.php file for ''" } } [1]=> array(6) { ["file"]=> string(58) "c:\usr\krasnal\www\sonda\Core\DB-1.7.6\PEAR-1.3.5\PEAR.php" ["line"]=> int(540) ["function"]=> string(8) "db_error" ["class"]=> string(8) "db_error" ["type"]=> string(2) "->" ["args"]=> array(4) { [0]=> int(-4) [1]=> int(1) [2]=> int(1024) [3]=> string(41) "Unable to include the DB/.php file for ''" } } [2]=> array(6) { ["file"]=> string(45) "c:\usr\krasnal\www\sonda\Core\DB-1.7.6\DB.php" ["line"]=> int(543) ["function"]=> string(10) "raiseerror" ["class"]=> string(4) "pear" ["type"]=> string(2) "::" ["args"]=> array(7) { [0]=> NULL [1]=> int(-4) [2]=> NULL [3]=> NULL [4]=> string(41) "Unable to include the DB/.php file for ''" [5]=> string(8) "DB_Error" [6]=> bool(true) } } [3]=> array(6) { ["file"]=> string(34) "c:\usr\krasnal\www\sonda\index.php" ["line"]=> int(10) ["function"]=> string(7) "connect" ["class"]=> string(2) "db" ["type"]=> string(2) "::" ["args"]=> array(0) { } } } ["callback"]=> NULL }


a przy wpisaniu var_dump(DB::connect($dns)) znow nie pokazuje sie nic.
Wiec być moze problem leży po stronie zmiennej $dns??
Zamieszczam wspomniana metod DB::connect() moze to w czyms pomoze:

  1. <?php
  2.  
  3. function &connect($dsn, $options = array())
  4. {
  5. $dsninfo = DB::parseDSN($dsn);
  6. $type = $dsninfo['phptype'];
  7.  
  8. if (!is_array($options)) {
  9. /*
  10.  * For backwards compatibility. $options used to be boolean,
  11.  * indicating whether the connection should be persistent.
  12.  */
  13. $options = array('persistent' => $options);
  14. }
  15.  
  16. if (isset($options['debug']) && $options['debug'] >= 2) {
  17. // expose php errors with sufficient debug level
  18. include_once "DB/${type}.php";
  19. } else {
  20. @include_once "DB/${type}.php";
  21. }
  22.  
  23. $classname = "DB_${type}";
  24. if (!class_exists($classname)) {
  25. $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
  26. "Unable to include the DB/{$type}.php"
  27. . " file for '$dsn'",
  28. 'DB_Error', true);
  29. return $tmp;
  30. }
  31.  
  32. @$obj =& new $classname;
  33.  
  34. foreach ($options as $option => $value) {
  35. $test = $obj->setOption($option, $value);
  36. if (DB::isError($test)) {
  37. return $test;
  38. }
  39. }
  40.  
  41. $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
  42. if (DB::isError($err)) {
  43. $err->addUserInfo($dsn);
  44. return $err;
  45. }
  46.  
  47. return $obj;
  48. }
  49.  
  50.  
  51. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 14.08.2025 - 19:25