Afficher un message
Vieux 26/02/2008, 16h39   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: -> [PHP5]: Problem with mysql_fetch_object trying to convertto int???

Steve JORDI wrote:
> Hi,
>
> I am currently moving a PHP4 application to PHP5 and I run across a
> strange problem and don't understand why it causes error messages.
>
> Here is what I have.
> In a class I have the following
>
> class dbConnection {
> private $result ;
> private $linkID ;
> private $query ;
> public $row ;
> static private $instance ; // Singleton
> ...
>
> function &getRow() {
> if( !($this->row = mysql_fetch_object($this->result)) )
> $this->row = 0 ;
> return $this->row ;
> }
> }
>
> Then in my application I have the following (it's in another class):
>
> class Welcome {
>
> private $db = 0 ;
> ...
> $this->db = dbConnection::getInstance() ;
> $this->db->connect("") ;
> ...
>
>
> // Parse data until no more rows are available
> while( ($this->row = $this->db->getRow() ) != 0 ) {
> $this->myVar1 = $this->row->theVar1 ;
> $this->myVar2 = $this->row->theVar2 ;
> /// blah blah
> }
>
> The problem is on while line.
> The error message is
> Notice: Object of class stdClass could not be converted to int in
> /[...]/jorditests/[myappname]/class_welcome.php on line 270
>
>
> This works without problem in PHP4. Not in PHP5.
> In PHP5, I then can get the data out of the $row variable and the
> result is correct. But why the convertion Notice warning?
>
> (Note that in PHP4 I have MySQL 4, and on the PHP5 server, MySQL 5)
>
> Any clue why?
>
>
> Thanks for any .
>
> Sincerely,
> Steve JORDI
>
> (Remove the K_I_L_LSPAM from my email address)
> ------------------------------------------------
> 1197 Prangins Email: stevejordiK_I_L_LSPAM@hotmail.com
> Switzerland WWW: www.sjordi.com
> ------------------------------------------------
> Volcanoes at www.sjordi.com/volcanoes
> MovieDB at www.sjmoviedb.com
> ------------------------------------------------
>


The message is correct. You're checking an object returned by your
getRow() function and then attempting to compare that object to integer
zero. There is no conversion for the two.

Rather, try returning false instead of zero from your function, and just
checking for false/not false, i.e.

while($this->row = $this->db->getRow())

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
 
Page generated in 0,05677 seconds with 9 queries