PEAR DB problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

PEAR DB problem

Post by basdog22 »

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

Code: Select all

<?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>';
    }
?>
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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$dbase= 'MySQL'; needs to be$dbase= 'mysql';

Or at least it does on my system anyway ;)
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

already done that. I was playing with it and made it MySQL to test :?

Nothing happens even if i change it to mosql 8O

anything wrong with my mysql installation??? Regular connect goes ok
eg:

Code: Select all

<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="root";
$dbname="zeuscms_02";
//Connect to the database//
$connect = mysql_connect($dbhost, $dbuser, $dbpass, $dbname)or die(mysql_error());
mysql_select_db($dbname, $connect)or die(mysql_error());
$query=mysql_query("select * from news");
while($row=mysql_fetch_array($query))
{
	$i=$row['headline'];
	echo $i;
}
?>
works fine .
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Can't see anything else obviously wrong.
Try putting error_reporting(E_ALL); as the first line of the script (after <?php) and see if there's any errors/warnings you're not seeing.
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

No error, no warning... :x

I think i dl the class again :roll:

maybe another version
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might need/want ini_set('display_errors','1') too...
Post Reply