While Loop Problem

While Loop Problem

am 21.11.2007 06:28:04 von Jesse Burns aka jburns131

I've got a coding problem here that I could use some help with.

Here's my db class (the config.php only has db connection info):

************************************************************ ********


// db_handler.inc

require_once("config.php");

class db {

var $mySQLresult;

function db() {

$this->dbConn = mysql_connect(DB_HOST, DB_USER, DB_PW);
mysql_select_db(DB_NAME, $this -> dbConn) or
die(mysql_error());
}

function db_Select($tables, $columns="'*'", $conditions="") {

$sql = "SELECT ".$columns." FROM ".$tables." ".$conditions;
$row = mysql_query($sql, $this -> dbConn) or
die(mysql_error());
$this->mySQLresult = $row;
}

function db_Fetch($type = MYSQL_BOTH) { //MYSQL_ASSOC
$row = mysql_fetch_array($this -> mySQLresult, $type) or
die(mysql_error());
if ($row) {
return $row;
} else {
return FALSE;
}
}
}

?>

************************************************************ ********

Here's the code I'm executing:

************************************************************ ********


require_once("includes/db_handler.inc");
require_once("includes/config.php");

echo "Hit 1
";

$sql = new db;
$result = $sql -> db_Select(DB_TABLE_ORG_INFO);
while ($row = $sql -> db_Fetch()) {

$organization_disclaimer =
$row['organization_disclaimer'];
}

echo "Hit 2
";

?>

************************************************************ ********

For some reason, the while loop is halting execution and won't display
"echo "Hit 2
";". The script just stops executing.

Any idea's why?

I'm using php5

Re: While Loop Problem

am 21.11.2007 11:18:10 von luiheidsgoeroe

On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131 =

wrote:
> I've got a coding problem here that I could use some help with.

> $row =3D mysql_fetch_array($this -> mySQLresult, $type) or =

> die(mysql_error());

Don't use 'or die()' here. If there are no further results (rows are =

finished), mysql_fetch_array() will return false, the die() will be =

executed, with nothing to display as there is no mysql_error(), it's jus=
t =

worked correctly.

And don't die() in production. Log the error, and degrade as gracefull a=
s =

you can.
-- =

Rik Wasmus

Re: While Loop Problem

am 24.11.2007 20:32:13 von Jesse Burns aka jburns131

Sorry for the delay in response, I've had trouble with my connection.

That was my problem. Thank you very much for the help and advise.

I hope you and everyone else had a great holiday.


"Rik Wasmus" wrote in message
news:op.t14z8k1c5bnjuv@metallium.lan...
On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
wrote:
> I've got a coding problem here that I could use some help with.

> $row = mysql_fetch_array($this -> mySQLresult, $type) or
> die(mysql_error());

Don't use 'or die()' here. If there are no further results (rows are
finished), mysql_fetch_array() will return false, the die() will be
executed, with nothing to display as there is no mysql_error(), it's just
worked correctly.

And don't die() in production. Log the error, and degrade as gracefull as
you can.
--
Rik Wasmus

Re: While Loop Problem

am 25.11.2007 02:10:32 von luiheidsgoeroe

> "Rik Wasmus" wrote in message
> news:op.t14z8k1c5bnjuv@metallium.lan...
> On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
> wrote:
>> I've got a coding problem here that I could use some help with.
>
>> $row =3D mysql_fetch_array($this -> mySQLresult, $type) or
>> die(mysql_error());
>
> Don't use 'or die()' here. If there are no further results (rows are
> finished), mysql_fetch_array() will return false, the die() will be
> executed, with nothing to display as there is no mysql_error(), it's j=
ust
> worked correctly.
>
> And don't die() in production. Log the error, and degrade as gracefull=
as
> you can.
On Sat, 24 Nov 2007 20:32:13 +0100, Jesse Burns aka jburns131 =

wrote:
> Sorry for the delay in response, I've had trouble with my connection.
>
> That was my problem. Thank you very much for the help and advise.
>
> I hope you and everyone else had a great holiday.

You're welcome, there was no holiday in The Netherlands I'm aware off, =

however, I'll finally have 1 week of in 2 weeks, and I'll make the most =
of =

it :)
-- =

Rik Wasmus