While Loop Problem - PHP
This is a discussion on While Loop Problem - PHP ; 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):
********************************************************************
<?php
// db_handler.inc
require_once("config.php");
class db {
var $mySQLresult;
function db() {
$this->dbConn = mysql_connect(DB_HOST, ...
-
While Loop Problem
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):
********************************************************************
<?php
// 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:
********************************************************************
<?php
require_once("includes/db_handler.inc");
require_once("includes/config.php");
echo "Hit 1<br />";
$sql = new db;
$result = $sql -> db_Select(DB_TABLE_ORG_INFO);
while ($row = $sql -> db_Fetch()) {
$organization_disclaimer =
$row['organization_disclaimer'];
}
echo "Hit 2<br />";
?>
********************************************************************
For some reason, the while loop is halting execution and won't display
"echo "Hit 2<br />";". The script just stops executing.
Any idea's why?
I'm using php5
-
Re: While Loop Problem
On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
<jburns131@gmail.com> 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
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" <luiheidsgoeroe@hotmail.com> wrote in message
news
p.t14z8k1c5bnjuv@metallium.lan...
On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
<jburns131@gmail.com> 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
> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
> news
p.t14z8k1c5bnjuv@metallium.lan...
> On Wed, 21 Nov 2007 06:28:04 +0100, Jesse Burns aka jburns131
> <jburns131@gmail.com> 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 gracefullas
> you can.
On Sat, 24 Nov 2007 20:32:13 +0100, Jesse Burns aka jburns131
<jburns131@jbwebware.com> 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
Similar Threads
-
By Application Development in forum c++
Replies: 6
Last Post: 11-15-2007, 08:30 AM
-
By Application Development in forum Java
Replies: 1
Last Post: 10-12-2007, 06:05 AM
-
By Application Development in forum lisp
Replies: 7
Last Post: 08-01-2007, 10:17 AM
-
By Application Development in forum vhdl
Replies: 8
Last Post: 07-26-2007, 03:25 PM
-
By Application Development in forum Perl
Replies: 6
Last Post: 10-01-2003, 12:15 PM