Re: php 4 script with php 5.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Quoting Torgny Bjers <torgny@xxxxxxxxxxx>:

> Don't top-post (on mailing lists, always respond below the other
> person's post). Please see below for my reply.
>
> Dwayne Hottinger wrote:
>
> >Thanks Torgny,
> >Im a real newby here at php scripting.  What should I put in the (....)?
> >Copying the snip into the script complains about that.  This is in a db.php
> >which defines how another script should utilize the database.  I could copy
> the
> >db.php into an email for someone to look over.
> >
> >thanks,
> >
> >ddh
> >
> >
> >Quoting Torgny Bjers <torgny@xxxxxxxxxxx>:
> >
> >
> >
> >>Dwayne Hottinger wrote:
> >>
> >>
> >>
> >>>I am trying to transfer some databases and php scripts that populate them
> to
> >>>
> >>>
> >>a
> >>
> >>
> >>>new server.  Server is running Fedora core 4 with mysql 4.x and php 5.0.5.
> >>>Original scripts were writen with php 4.x and worked fine.  I get a PHP
> >>>
> >>>
> >>Notice:
> >>
> >>
> >>>Undefined variable: return_array when running them on the new server and
> >>>
> >>>
> >>the
> >>
> >>
> >>>database doesnt get populated.  Mysql database and mysql user rights seem
> to
> >>>
> >>>
> >>be
> >>
> >>
> >>>correct.  Do I have to rewrite the script for php 5.x or should it work
> and
> >>>
> >>>
> >>I
> >>
> >>
> >>>need to dig for another problem?  Im quite new to php and dont know quite
> >>>
> >>>
> >>which
> >>
> >>
> >>>way to go for help. I hope I have posted this on the right list.
> >>>
> >>>ddh
> >>>
> >>>
> >>>
> >>Hello Dwayne,
> >>
> >>This is easy enough, all you need to do is define return_array. I've
> >>included an example here, it's mailer code, but, should illustrate what
> >>you need to do.
> >>
> >>function test()
> >>{
> >>$return_array = null;
> >>if (...) {
> >>    $return_array = $db->getAll("SELECT * FROM table", DB_FETCHMODE_ASSOC);
> >>}
> >>return $return_array;
> >>}
> >>
> >>That means, you need to assign or indicate that return_array exists
> >>before you use it in something like return or other PHP function. Your
> >>php.ini file for PHP 4 could have been more forgiving coming to these
> >>notices/warnings.
> >>
> >>Warm Regards,
> >>Torgny Bjers
> >>
> >>
>
> The (...) was just an illustration if you had an if statement that
> didn't fire, then $return_array wouldn't be defined at all. Just put
> $return_array = null; in the top of the script somewhere so that it is
> defined at all times, that way you don't have to worry about the actual
> notice about it not being defined.
>
> You can then also make a simple check to see if it is an array, for
> instance:
>
> if (!emtpy($return_array) && is_array($return_array)) {
>     /* Code to do something with $return_array */
> }
>
> That would be a good idea if you for instance are going to iterate the
> items in the array somewhere, if you don't check first, you might
> attempt to iterate a variable that doesn't contain an array but null,
> then PHP will yell at you for that.
>
> You are welcome to mail the script to me privately and I can take a look
> at it for you.
>
> Warm Regards,
> Torgny
>
>
Torgny,

Sorry about the top posting.  Force of habit.  I'll look over the info you have
given me and get back with you.  Thanks I really appreciate the help

ddh


--
Dwayne Hottinger
Network Administrator
Harrisonburg City Public Schools

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux