Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2006
    Posts
    40

    PHP 5.2.8 Problem

    I have a PHP script that I had developed for me. It's a year or two old, and I'm pretty sure it was made for PHP 4. I'm having a lot of trouble getting it to work with PHP 5, more importantly PHP 5.2.8.

    An example of an error:

    Fatal error: Cannot use string offset as an array on line 4.

    Here is the beginning of that file, including line 4.

    PHP Code:
    $db = new DB();
    $cheapestShared $db->SelectQuery("plan,price","*","WHERE plan.plan_type = 1 AND plan.plan_id = price.plan_id_FK","","ORDER BY price.price_value ASC LIMIT 1",false);
    $cheapestSharedFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestShared[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 1"); 
    Is this an easy fix? I can do the changes my myself, but only to a limited extent. I don't have a problem with hiring someone (I know to post in another forum) to update to PHP 5. However, if this is a simple fix then I would rather do it myself.

    Hopefully someone can take the time to share some light on this.

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Looks like it's complaining because of the use of $variable[0][0] when $variable isn't a 2-dimensional array. I think you'd need to look at what $db->SelectQuery is returning (var_dump or print_r would help for this) and either:
    • change the program to use the result properly, or
    • change SelectQuery to return something that works with the existing way the program tries to use it.

    Probably not a simple fix either way.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Aug 2006
    Posts
    40
    Thanks for taking the time to reply.

    I'm not this experienced with PHP to do the changes. What would be a acceptable price before I make a new thread looking for someone? Here is the rest of the PHP in that file to get an idea:

    PHP Code:
    <?php include_once('db.php');
    $db = new DB();
    $cheapestShared $db->SelectQuery("plan,price","*","WHERE plan.plan_type = 1 AND plan.plan_id = price.plan_id_FK","","ORDER BY price.price_value ASC LIMIT 1",false);
    $cheapestSharedFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestShared[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 1");
    $cheapestSharedYesNoFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestShared[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 2","","");

    $cheapestVPS $db->SelectQuery("plan,price","*","WHERE plan.plan_type = 4 AND plan.plan_id = price.plan_id_FK","","ORDER BY price.price_value ASC LIMIT 1",false);
    $cheapestVPSFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestVPS[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 1");
    $cheapestVPSYesNoFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestVPS[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 2","","");

    $cheapestDedicated $db->SelectQuery("plan,price","*","WHERE plan.plan_type = 3 AND plan.plan_id = price.plan_id_FK","","ORDER BY price.price_value ASC LIMIT 1",false);
    $cheapestDedicatedFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestDedicated[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 1");
    $cheapestDedicatedYesNoFeatures $db->SelectQuery("feature,plan_has_feature","*","WHERE plan_has_feature.plan_id_FK = " $cheapestDedicated[0][0] . " AND feature.feature_id = plan_has_feature.feature_id_FK AND feature.feature_type = 2","","");

    ?>
    Yes, there is more to this script than just that file, unfortunately.

  4. #4
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    How much should it cost? Too hard a question, because rates differ greatly and there's no way to tell from what you've posted how much work the job involves.

    Why don't you try fixing it yourself? Perhaps you'll get it free and learn along the way.

    You could start by changing the beginning of that file like this and posting the results:
    PHP Code:
    $db = new DB();
    $cheapestShared $db->SelectQuery("plan,price","*","WHERE plan.plan_type = 1 AND plan.plan_id = price.plan_id_FK","","ORDER BY price.price_value ASC LIMIT 1",false);
    print_r($cheapestShared);
    exit; 
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  5. #5
    Join Date
    Aug 2006
    Posts
    40
    I've been experimenting with this the past day. It works fine with PHP 4 (of course) and PHP 5.2.6. The problem is, my provider is using 5.2.8.

    Are there significant changes between 5.2.6 to 5.2.8 in terms of code standards and what is accepted?

  6. #6
    Join Date
    Jan 2008
    Location
    England
    Posts
    573
    5.2.8 was just a security fix, so it would of been something in 5.2.7:
    http://www.php.net/releases/5_2_7.php

    Post the results of what foobic said, it's likely that its a simple fix.

  7. #7
    Join Date
    Aug 2006
    Posts
    40
    Quote Originally Posted by foobic View Post
    How much should it cost? Too hard a question, because rates differ greatly and there's no way to tell from what you've posted how much work the job involves.

    Why don't you try fixing it yourself? Perhaps you'll get it free and learn along the way.

    You could start by changing the beginning of that file like this and posting the results:
    Result was:

    Code:
    Array (     [0] => Array         (             [0] => 15             [1] => Basic             [2] => link             [3] => 1             [4] => 37             [5] => 1             [6] => 3.95             [7] => 15             [8] => 5.00         )  )
    Sorry for the delay.

    This script is really confusing me in terms of what PHP version it wants to work with. My local server has PHP 5.2.6 with Apache/2.2.11 and this script runs with no issues at all, it's perfect. The server I am attempting to get this to work on is a cPanel install with PHP 5.2.6 and Apache/2.0.63 and it is the one I am having troubles with.

    I notice the difference in Apache versions but does that really have anything to do with PHP and how it was coded?

    Thanks again for all your tips and advice.

  8. #8
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Strange. It appears that function is returning a 2D array, so why the error message...

    I only have 5.2.9 / 5.2.10 running but I don't see why something as basic as this should change between minor versions.

    What does this little test script give you?
    PHP Code:
    <?php
    $ary 
    = Array (Array(15"Basic""link"13713.95155.00  )  );
    print_r($ary);
    print 
    $ary[0][0];
    ?>
    Is it possible that one of your systems is missing some data or has a corrupted database? SelectQuery is being called multiple times - perhaps sometimes it returns no data, and that's when you see the error. You could check using the is_array function.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  9. #9
    Join Date
    Aug 2006
    Posts
    40
    That script returns:
    Code:
    Array (     [0] => Array         (             [0] => 15             [1] => Basic             [2] => link             [3] => 1             [4] => 37             [5] => 1             [6] => 3.95             [7] => 15             [8] => 5         )  ) 15
    Well, like I said the script runs fine on PHP 5.2.6 with Apache/2.2.11 (local server).

    I even went a step further and used another server with PHP 5.2.6 and Apache/2.0.63 (to duplicate the cPanel server I am trying to use) and still received the same errors. This makes me think it is the script or Apache.

    It's a .30MB database, and it isn't corrupted as far as I can tell.

    This is very puzzling.

  10. #10
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    At this point I really doubt that it's a version issue (Apache or PHP). I still think the most likely would be a difference in your databases, combined with poor-quality code (not handling the exception properly).

    Try just adding "print_r($cheapestShared);" (without the exit line afterwards) before the line that errors out and check the value it prints immediately before the error message.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  11. #11
    Join Date
    Aug 2006
    Posts
    40
    Hmm, very very odd. Now it seems to be working, without that above print code.

    I did repair the database, perhaps that really was it? Wouldn't it have displayed a different error message?

  12. #12
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Quote Originally Posted by Andrews860 View Post
    Wouldn't it have displayed a different error message?
    It depends entirely on what's going on in that SelectQuery routine. Perhaps it returns a string (eg. error message) in the event of an error or no results coming back from the database. So when your main program tries to treat that result as an array you get the error you posted.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  13. #13
    Join Date
    Aug 2006
    Posts
    40
    That would make sense.

    Thank you, Chris, for all your help with this issue. You've been a life safer.

Similar Threads

  1. [problem] Invalid URI in request (httpd problem)
    By xserverx in forum Hosting Security and Technology
    Replies: 0
    Last Post: 05-14-2008, 11:17 AM
  2. Domain Problem , Hosting Problem or Security Problem?
    By xoleno in forum Hosting Security and Technology
    Replies: 0
    Last Post: 03-31-2008, 05:41 AM
  3. Software Problem on Dedicated Server...Not a Problem on Shared??
    By ekusteve in forum Hosting Security and Technology
    Replies: 4
    Last Post: 06-14-2005, 12:35 PM
  4. php problem? Apache problem? Mime? Script can't do upload....
    By galacnet in forum Hosting Security and Technology
    Replies: 7
    Last Post: 05-30-2005, 11:15 AM
  5. Large problem with domains displaying wrong problem.
    By NationHosts in forum Hosting Security and Technology
    Replies: 3
    Last Post: 01-20-2004, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •