Jump to content


Photo

Upgrade to php 5


  • Please log in to reply
4 replies to this topic

#1 leeish

leeish
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 01:42 PM

I have what I hope to be a rather simple question.  We have a website here that is running from what I understand php 4.  Everything works perfect of course because all of the code was written in Dreamweaver and being tested of course and works.  We are in the process of setting up a new server which from what I understand is running php 5.  We have not yet set it up to broadcast but we have it accessable on our network.  All of the mysql tables are on the same machine.  Here is the deal, we copied the page over and we are getting a bunch of errors like the folloring:

Warning: Invalid argument supplied for foreach() in /usr/local/apache/htdocs/solomon/lib/Db.php on line 1185

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/solomon/lib/Db.php on line 1175

Warning: Invalid argument supplied for foreach() in /usr/local/apache/htdocs/solomon/lib/Db.php on line 1191

I am assuming it is a difference in the code that needs to be changed from PHP 4 to PHP 5.  I have been looking for a list of things that changed between the two versions and I don't find anything.  My question is what is going on here.  In the "not a valid MySQL resource error" everyone seems to say that is it because it's not pulling information.  I know in a few of the pages the code is set for example:

if (!mysql_num_rows($result)){
RUN CODE HERE
}

So I want to check to see if it pulls something and if not do something else... Well I get an error similar to the one above on the line that has the mysql_num_rows line of code.  Are there things that I have to code differently in php 5.  The web site works 100% on the old server, so I know the code is good.  And advice I am lost at where the problem is if there is one...  If you want an example of one check out www.missionvina.com.

It appears that it is giving me errors when the information is not there for example.  I have a function:
get_info($x);

Sometimes I run the function get_info(1) and sometimes I just run it get_info().  Either way i pull info sometimes one way and othertimes I need the argument in ().  These errors I just want to dissappear because I know all of the code works as I need it.  So is there a way to just turn off the errors so they don't show up?  Or do I need to make seperate functions for when I don't want to run the argument for example.  Does my code have to be flawless to run on PHP 5?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 02:21 PM

No, it doesn't have to be flawless (although all code should be ;)

If you're working from a different server and getting "invalid argument" or "invalid resource", I'd question whether you're talking to your database correctly or not.  Can you verify that?

Info: PHP Manual


#3 leeish

leeish
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 02:39 PM

Well the pages work on one server and not the other.  I still pull the information on the new server though just I get errors where is doesn't pull any, the thing is that where it doesn't pull info I don't want it to.  Example:

$count_confirmations = count_confirmations($_SESSION['info']['SectorID']);

Sometimes when accessing the page the people have a confirmation that is pulled from my database in the count_confirmations function.  Othertimes they don't have one, and that is fine, I just want the page to check to see if they did.  The web page however, if it runs the functions and finds that there are no confirmations gives me the error, but if there was a confirmation it wouldn't give me the error.

Another example:

function A

If there is no result for function A
{
Run this command
}

It gives me an error when I check to see if there is a result for function A.  It's ok if it's NULL, so why the error.



#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 02:44 PM

Well, it all depends on how you trap your errors and what kind of error reporting  you have enabled in the php.ini file.  You really shouldn't be designing a code that "could have errors" that you just ignore.  You should ALWAYS trap errors and if they don't matter, you move on appropriately, but if they do, you should have an error log or a system that emails you the errors.

Info: PHP Manual


#5 leeish

leeish
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 04:59 PM

It appears that PHP 5 is just showing all the mistakes in the code. A lot of the erorrs are just pointing out useless code that doesn't pull bad results but is pointless, and most of which I am taking out.  I guess I should be happy that it's finding all my errors for me so I can clean up the mess.  Thanks for the help anyway.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users