PEAR DB Help

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

aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

PEAR DB Help

Post by aliasxneo »

I am currently running Windows XP Pro with PHP 5.2 and MySQL 5.0 installed. My remote server is a UNIX system with PHP 5.1 installed and MySQL 5.0 installed. Here is the code I'm trying to run:

Code: Select all

// Load up the PEAR DB class //
		$this->mysql = DB::connect(sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE));
		echo "hello";
On my computer it works perfectly fine, returns a db_mysql class and no errors. On my server it does nothing. I put echo "hello" there as a test, and when I run the script I don't even see "hello" get printed to the screen, for some reason it's just screwing the entire script up. I checked the USERNAME, PASSWORD, etc. values against the ones I have in CPANEL and they match. Does anyone know what might be causing this problem? Thanks.

Cheers,
- Josh
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is PEAR and PEAR::DB installed on the server? Can you take a look at the error logs (available through cpanel) to see what errors php may be throwing up?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$dsn = sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE);
echo '<div>connecting to: ', $dsn, "</div>\n";
$this->mysql = DB::connect($dsn);
if (PEAR::isError($this->mysql)) {
	echo "<div>an error occured while connection to the database.<pre>\n";
	var_dump($this->mysql);
	die('</pre></div>');
}
echo "hello";
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post by aliasxneo »

I already tried all that, there is no use in adding an error handler when it won't even go to that part of the script. Like I said, it won't even print "hello" out, it just get's stuck and stops executing.

You can see it here: http://www.coolmailengine.com

As you can see the page is blank, there should be content, but there isn't. I'll show you the exact code I have right now:

Code: Select all

echo "test";
		$dsn = sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE); 
		$this->mysql = DB::connect($dsn);
		if (PEAR::isError($this->mysql))
		{
			die("MYSQL ERROR: " .  $this->mysql->getMessage() . "<br />DEBUG: " . $this->mysql->getDebugInfo());
		}
		echo "test1";
Now, go visit the page (http://www.coolmailengine.com). Watch, you'll see "test" on the page, but you won't see "test1".
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Oops, I missed the "don't" in
I don't even see "hello" get printed
Then feyd's probably right.
Try

Code: Select all

error_reporting(E_ALL); ini_set('display_errors', true);
class_exists('DB') or die('there is no class "DB"');

echo "test";
$dsn = sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE);
$this->mysql = DB::connect($dsn);
if (PEAR::isError($this->mysql))
{
      die("MYSQL ERROR: " .  $this->mysql->getMessage() . "<br />DEBUG: " . $this->mysql->getDebugInfo());
}
echo "test1";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

feyd wrote:Can you take a look at the error logs (available through cpanel) to see what errors php may be throwing up?
Image
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post by aliasxneo »

Where exactly would these errors be located in CPANEL? I see "Error Logs" but there is nothing in there except:
[Mon Dec 18 13:25:09 2006] [error] [client 67.180.131.245] File does not exist: /home/coolmail/public_html/404.shtml
[Mon Dec 18 13:25:09 2006] [error] [client 67.180.131.245] File does not exist: /home/coolmail/public_html/favicon.ico
[Mon Dec 18 13:14:57 2006] [error] [client 88.72.15.128] File does not exist: /home/coolmail/public_html/404.shtml
[Mon Dec 18 13:14:57 2006] [error] [client 88.72.15.128] File does not exist: /home/coolmail/public_html/favicon.ico
[Mon Dec 18 13:11:27 2006] [error] [client 67.180.131.245] File does not exist: /home/coolmail/public_html/404.shtml
[Mon Dec 18 13:11:27 2006] [error] [client 67.180.131.245] File does not exist: /home/coolmail/public_html/favicon.ico
This was my code:

Code: Select all

// Load up the PEAR DB class //
		error_reporting(E_ALL); ini_set('display_errors', true);
		class_exists('DB') or die('there is no class "DB"'); 
		
		echo "test";
		$dsn = sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE); 
		$this->mysql = DB::connect($dsn);
		if (PEAR::isError($this->mysql))
		{
			die("MYSQL ERROR: " .  $this->mysql->getMessage() . "<br />DEBUG: " . $this->mysql->getDebugInfo());
		}
		echo "test1";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If the error logs aren't being helpful, I may suggest opening a file and writing debug information to it. Something similar to

Code: Select all

$f = fopen('some/path/to/a/file/to/log.txt', 'at');
if($f)
{
  fwrite($f, date('[Y-m-d H] ') . 'some debug info' . PHP_EOL);
  fwrite($f, date('[Y-m-d H] ') . 'some more debug info' . PHP_EOL);
  fwrite($f, date('[Y-m-d H] ') . 'even more debug info' . PHP_EOL);
}
Also, could you run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post by aliasxneo »

Here is the code you wanted me to run:

http://www.coolmailengine.com/test.php
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

aliasxneo wrote:This was my code:

Code: Select all

// Load up the PEAR DB class //
		error_reporting(E_ALL); ini_set('display_errors', true);
		class_exists('DB') or die('there is no class "DB"'); 
		
		echo "test";
		$dsn = sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE); 
		$this->mysql = DB::connect($dsn);
		if (PEAR::isError($this->mysql))
		{
			die("MYSQL ERROR: " .  $this->mysql->getMessage() . "<br />DEBUG: " . $this->mysql->getDebugInfo());
		}
		echo "test1";
and it still only prints test and then falls silent?
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post by aliasxneo »

Yes, I have never seen anything like it before, which is why I need help :p
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

That's strange.
Another test:

Code: Select all

error_reporting(E_ALL); ini_set('display_errors', true);

echo "<div>wrong mysql_connect</div>\n"; flush();
$mysql = mysql_connect('lalala', 'nouser', 'wrongpassword');
echo "<div>mysql_error</div>\n"; flush();
echo "<div>", mysql_error(), "</div>\n"; flush();

echo "<div>mysql_connect</div>\n"; flush();
$mysql = mysql_connect(HOST, USERNAME, PASSWORD) or die(mysql_error());
echo "<div>mysql_select_db</div>\n"; flush();
mysql_select_db(DATABASE, $mysql) or die(mysql_error());
echo "<div>mysql_close</div>\n"; flush();
mysql_close($mysql); unset($mysql);
echo "<div>Done.</div>\n"; flush();

echo "<div>sprintf</div>\n"; flush();
$dsn = sprintf("%s://%s:%s@%s/%s", TYPE, USERNAME, PASSWORD, HOST, DATABASE);
echo "<div>DB::connect</div>\n"; flush();
$mysql = DB::connect($dsn);
echo "<div>DB::isError</div>\n"; flush();
if (DB::isError($mysql)) {
	die("MYSQL ERROR: " .  $mysql->getMessage() . "<br />DEBUG: " . $mysql->getDebugInfo());
}
echo "<div>Done.</div>\n"; flush();
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post by aliasxneo »

http://www.coolmailengine.com/

Results of your test. Mysql connects works fine, errors work fine, still stops at DB::connect.
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post by aliasxneo »

Some extra information:

This code is from my framework that I am developing. In the framework I have the DB class stored in a another folder, I don't rely on the system having PEAR installed. In my index.php file I have:

Code: Select all

require_once("includes/system/PEAR/DB.php");
In the /includes/system/PEAR directory the following files exist:

PEAR.php
DB.php
DB
common.php
dbase.php
fbsql.php
ibase.php
ifx.php
msql.php
mysql.php
mysqli.php
oci8.php
odbc.php
pgsql.php
sqlite.php
storage.php
sybase.php
doc
IDEAS
STATUS
MAINTAINERS
TESTERS
tests


I'm also using the latest version of PEAR DB. I'm not sure if any of that affects anything, I don't think it should.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Sorry, I'm clueless.
Post Reply