[Solved] PEAR DB problem

  • basdog22
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Hellas

Post 3+ Months Ago

Hi,
I am trying to use PEARs abstraction layer and i have this code:

PHP Code: [ Select ]
 
<?php
 
//The database configuration file
 
//It connects the user to the DB
 
 
 
//Your SQL type
 
$dbase= 'MySQL';
 
//Your bduser string
 
$user = 'root';
 
//Your db pass
 
$pass = 'root';
 
//Your db host
 
$host = 'localhost';
 
//Your DB name
 
$db_name = 'zeuscms_02';
 
 
 
//This is the string that will be used for the connection
 
$dsn = '$dbase://$user:$pass@$host/$db_name';
 
//Require the Abstraction layer
 
require_once "dblayer/DB.php";
 
//Connect to the database
 
$db = DB::connect("$dbase://$user:$pass@$host/$db_name");
 
 
 
//If there is an error warn the user
 
if (DB::isError($db))
 
{
 
    die ($db->getMessage());
 
}
 
 
 
$sql = "select * from news";
 
    $demoResult = $db->query($sql);
 
    while ($demoRow = $demoResult->fetchRow(DB_FETCHMODE_ASSOC)) {
 
        echo $demoRow['headline'] . '<br>';
 
    }
 
?>
  1.  
  2. <?php
  3.  
  4. //The database configuration file
  5.  
  6. //It connects the user to the DB
  7.  
  8.  
  9.  
  10. //Your SQL type
  11.  
  12. $dbase= 'MySQL';
  13.  
  14. //Your bduser string
  15.  
  16. $user = 'root';
  17.  
  18. //Your db pass
  19.  
  20. $pass = 'root';
  21.  
  22. //Your db host
  23.  
  24. $host = 'localhost';
  25.  
  26. //Your DB name
  27.  
  28. $db_name = 'zeuscms_02';
  29.  
  30.  
  31.  
  32. //This is the string that will be used for the connection
  33.  
  34. $dsn = '$dbase://$user:$pass@$host/$db_name';
  35.  
  36. //Require the Abstraction layer
  37.  
  38. require_once "dblayer/DB.php";
  39.  
  40. //Connect to the database
  41.  
  42. $db = DB::connect("$dbase://$user:$pass@$host/$db_name");
  43.  
  44.  
  45.  
  46. //If there is an error warn the user
  47.  
  48. if (DB::isError($db))
  49.  
  50. {
  51.  
  52.     die ($db->getMessage());
  53.  
  54. }
  55.  
  56.  
  57.  
  58. $sql = "select * from news";
  59.  
  60.     $demoResult = $db->query($sql);
  61.  
  62.     while ($demoRow = $demoResult->fetchRow(DB_FETCHMODE_ASSOC)) {
  63.  
  64.         echo $demoRow['headline'] . '<br>';
  65.  
  66.     }
  67.  
  68. ?>




Can someone please tell me why i get nothing??

Even if i change mysql string to mssql (mssql does not exist on my system) i don't get a message. I only get an error when i change mysql to smysql or something.
  • Sabu
  • Beginner
  • Beginner
  • Sabu
  • Posts: 47

Post 3+ Months Ago

well.. I don't know a thing about PEARs, except that they may seem sweet when you bite.. but dig too deep and they get sour.

perhaps it's die()ing with an error, but the error message itself is blank? Or for some reason your demorow is returning an empty array
  • basdog22
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Hellas

Post 3+ Months Ago

I think its the connection thing. It seems it doesn't connect at all
  • basdog22
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Hellas

Post 3+ Months Ago

The problem was that i had the DB class file in a subdirectory of the site. When i placed it in the root dir everything works fine. :)

Thanks

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 39 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.