I am a beginner of PEAR. I've just follow a tutorial example and have done the following code:

<?
require_once("DB.php");

$db_type = 'localhost';
$db_user = 'sandman';
$db_pass = '123';
$db_name = 'test';

$dsn = $db_type . '://' . $db_user . ':' . $db_pass . '@' . strtoupper($db_type) . '/' . $db_name;
$db = DB::Connect($dsn);
$sql = 'SELECT * FROM link';
$rs = $db->query($sql);	//given by the tutorial
?>

But the error message show up:
Fatal error: Call to undefined function: query() in ...blah blah...

Can anyone point out my problem.

Thanks.

    hi

    would you send me the link to the tutorial , or book name?!
    becouse this code has no sense.

    it would be parsed like this:

    $dns=localhost://sandman:123@LOCALHOST/test
    ....
    

    does anyone understand it's meaning?

    but it will go trough this ... because it's just a variable, and php doesn't know this must be a URL.

    query() must be a function in DB.php.
    php has the "mysql_query()" function.

      3 months later

      Believe it or not, this error is generated when your database connection fails. No really, it is.

      To diagnose, add these lines to your code after your attempt to connect. This will tell you if your connection fails.

      if (DB::isError($db)) { // Check whether the object is a connection or an error.
      die($db->getMessage()); // Print out a message and exit if it's
      // an error object.
      }

      I noticed a potential problem in your connection string. -
      your connection string is missing the first portion - the type of database to which you are connecting. Posgresql connections should begin with pgsql:// while mysql connections are mysql://. This tells the DB class what type of connection to employ.

        The problem is that you need to define $db_type to 'mysql' and you need a new var $db_host to equal 'localhost'. Here is an example of a use :

        <?php
        require_once( 'DB.php' );
        define( 'MYDB_DSN', 'mysql://username:password@localhost/database' );
        
        function getDBConnection($dsn)
        {
         $aDB = DB::connect( $dsn );
         $aDB->setFetchMode( DB_FETCHMODE_ASSOC );
         return $aDB;
        }
        
        $aDB = getDBConnection( MYDB_DSN );
        $aSQL = "SELECT * FROM tablename";
        $aRows = $aDB->simpleQuery( $aSQL );
        $aRowCount = $aDB->numRows( $aRows );
        if ( is_int($aRowCount) && $aRowCount > 0)  {
         while( $aRow = $aDB->fetchRow( $aRows ) ) {
           print "------NEW ROW---------<br>\n";
           while ( list($key, $val) = each ($aRow)) {
             print "[ $key ] = $val<br>\n";
           }
         }
        }
        ?>
        

          Or, to fix your code:

          <?
          require_once("DB.php");
          $db_type = 'mysql';    
          $db_host = 'localhost'; $db_user = 'sandman'; $db_pass = '123'; $db_name = 'test'; $dsn = $db_type . '://' . $db_user . ':' . $db_pass . '@' . $db_host . '/' . $db_name; $db = DB::connect($dsn); $sql = 'SELECT * FROM link'; $rs = $db->simpleQuery($sql); ?>
            Write a Reply...