Jump to content

Upgrade to php 5


leeish

Recommended Posts

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?
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.