Page 1 of 1

PHP 4.4.4 to 5.2.6 broke my site!

Posted: Sat Jul 12, 2008 7:21 pm
by jayman30
My web host (Hostgator) upgraded from PHP 4.4.4 to 5.2.6 and from MySQL 4.1.22-standard to MySQL 5.0.51a-community. Now one of my hosted sites is broken. This site has been up and running fine for over a year. It is running an Easy Photo Store script

index.php is giving this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/photos/public_html/setting.php on line 63
MySQL server has gone away
I did a lot of troubleshooting on a MySQL forum and have discovered that the PHP5 code incompatibility is most likely responsible for this problem.

Here's the URL: http://www.photographybykh.com
However, the Site's Administration Section is still working fine: http://www.photographybykh.com/admin

Going directly to http://www.photographybykh.com/setting.php seems to result in an endless loop with no errors being displayed.

Here's my code from setting.php

Code: Select all

<? 
 
    include("admin/setting.php"); 
    require("libs/Smarty.class.php");     
 
    $smarty = new Smarty;     
    $smarty->compile_check = true;     
 
 
 
    $db_connect = mysql_connect($db_host, $db_username, $db_password); 
    mysql_select_db($db_name, $db_connect) || die(mysql_error()); 
     
    $sql_query     = "SELECT * FROM setup_category WHERE category_id = '$cat'"; 
    $result        = mysql_query($sql_query) or die(mysql_error()); 
    $row         = mysql_fetch_array($result); 
    $cat_id        = $row[category_id]; 
    $cat_parent    = $row[category_parent]; 
    $cat_path    = $row[category_path]; 
    $cat_level    = sizeof(explode("-", $cat_path)) - 1;     
    $cat_split    = explode("-", $cat_path); 
 
    $i             = 0; 
    $sql_query     = "SELECT * FROM setup_category ORDER BY category_pathname ASC"; 
    $result        = mysql_query($sql_query) or die(mysql_error()); 
    while($row     = mysql_fetch_array($result)) { 
     
        $category_id        = $row[category_id]; 
        $category_parent    = $row[category_parent]; 
        $category_name        = $row[category_name]; 
        $category_name_mod    = convert_rewrite($category_name); 
        $category_path         = $row[category_path]; 
        $category_level        = sizeof(explode("-", $category_path)) - 1; 
        $category_padding    = 10 * ($category_level - 1);     
        $category_path_tmp    = ""; 
 
 
 
        if ($status_url_rewrite == "yes") { 
           $category_url    = "gallery-$category_name_mod-$category_id-1-0-browse.php"; 
        } else { 
           $category_url    = "site_gallery.php?cat=$category_id"; 
        } 
 
 
         
        $category_sql        = ""; 
        $sql_query            = "SELECT * FROM setup_category WHERE category_path LIKE '-$category_path-%'"; 
        $result_1            = mysql_query($sql_query) or die(mysql_error()); 
        while($row_1         = mysql_fetch_array($result_1)) { 
         
            $sub_cat_id        = $row_1[category_id]; 
            $category_sql  .= " photo_category LIKE '%-$sub_cat_id-%' OR "; 
         
        } 
        $category_sql        = substr($category_sql, 0, strlen($category_sql) - 3); 
        if ($category_sql)     { $category_sql    = " photo_category LIKE '%-$category_id-%' OR $category_sql";     }  
        else                 { $category_sql    = " photo_category LIKE '%-$category_id-%'";                     } 
         
 
        $sql_query            = "SELECT * FROM photo WHERE $category_sql"; 
        $result_1            = mysql_query($sql_query) or die(mysql_error());     
        $category_photo        = mysql_num_rows($result_1); 
 
         
        if ($category_level == 1) { $category_color = " 
        "; } 
        if ($category_level == 2) { $category_color = "000000"; } 
        if ($category_level == 3) { $category_color = "000000"; } 
        if ($category_level == 4) { $category_color = "000000"; } 
        if ($category_level == 5) { $category_color = "000000"; } 
        if ($category_level == 6) { $category_color = "000000"; } 
        if ($category_level == 7) { $category_color = "000000"; } 
     
         
        for ($j = 1; $j <= $category_level - 1; $j++) {  
            $category_path_tmp    = $category_path_tmp . "-". $cat_split[$j]; 
        } 
     
         
        $category_found         = strpos($category_path, $category_path_tmp . "-"); 
        if ($category_found === false)     {  
           $category_status = 0;  
        } else {  
           $category_status = 1;  
        } 
 
 
 
        if ($category_level >= 1 && $category_level <= $cat_level + 1 && $category_status) { 
                 
            $arr_left_cat_id[$i]    = $category_id; 
            $arr_left_cat_name[$i]    = $category_name; 
            $arr_left_cat_link[$i]    = $category_url; 
            $arr_left_cat_left[$i]    = $category_padding; 
            $arr_left_cat_color[$i]    = $category_color; 
            $arr_left_cat_photo[$i]    = $category_photo; 
            $i++; 
 
            // $arr_left_cat_name[$i]    = $category_name . "<br>Level: $category_level<br>Path:$category_path<br>Tmp:$category_path_tmp<br>Found: $category_status<br>MainLevel : $cat_level<br><br>"; 
 
        } 
             
         
    } 
    mysql_close($db_connect); 
 
 
 
    // javascript right click protection 
    if ($web_right_click_protect == "yes") { 
        $web_javascript    = "<script language=\"javascript\" type=\"text/javascript\" src=\"javascript_rightclick.js\"></script>";     
    } 
     
 
    // smarty for meta tags 
    $smarty->assign("meta_title"            , $web_title            );                  
    $smarty->assign("meta_encoding"            , $web_encodings        );              
    $smarty->assign("meta_keyword"            , $web_keywords            );              
    $smarty->assign("meta_description"        , $web_desc                );              
    $smarty->assign("javascript_rightclick"    , $web_javascript        ); 
     
 
 
    // warning cookie               
    $smarty->assign("warning"                , $warning                );  
    $smarty->assign("activate_lightbox"        , $activate_lightbox    );  
 
    $smarty->assign("left_cat_id"            , $arr_left_cat_id        );              
    $smarty->assign("left_cat_name"            , $arr_left_cat_name    );      
    $smarty->assign("left_cat_link"            , $arr_left_cat_link    );      
    $smarty->assign("left_cat_left"            , $arr_left_cat_left    );      
    $smarty->assign("left_cat_color"        , $arr_left_cat_color    );      
    $smarty->assign("left_cat_photo"        , $arr_left_cat_photo    );      
     
    $smarty->assign("left_cust_id"            , $clogin_customer                );      
    $smarty->assign("left_cust_firstname"    , $clogin_customer_firstname    );      
    $smarty->assign("left_cust_lastname"    , $clogin_customer_lastname        );      
 
         
?>
Changing Line 63 from:

$category_photo = mysql_num_rows($result_1);


to

$category_photo = mysql_num_rows($result_1) or die(mysql_error());

Results in these error messages:
Warning: include(setting.php) [function.include]: failed to open stream: No such file or directory in /home/photos/public_html/index.php on line 5
 
Warning: include(setting.php) [function.include]: failed to open stream: No such file or directory in /home/photos/public_html/index.php on line 5
 
Warning: include() [function.include]: Failed opening 'setting.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/photos/public_html/index.php on line 5
 
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'photos'@'localhost' (using password: NO) in /home/photos/public_html/index.php on line 6
 
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/photos/public_html/index.php on line 7
Access denied for user 'photos'@'localhost' (using password: NO)
The access denied for user error has me confounded since everything is correct in database string files and I can log into the admin section of this site with no errors and the site was working fine until the PHP5 upgrade last night.

My customer is upset her site is dead, the developer is unavailable until Monday and Hostgator tech support is not responding to my support tickets--HELP!!

Re: PHP 4.4.4 to 5.2.6 broke my site!

Posted: Sat Jul 12, 2008 7:38 pm
by jaoudestudios
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/photos/public_html/setting.php on line 63
MySQL server has gone away
Your first error sounds like the mysql_query before it has no results, so the count has failed.

Adding the or die..., I dont think is your solution.

If you do not want the mysql_num_rows to run unless the query before has succeeded then use this code (however, I am surprised you are getting any errors on a production server, usually they are turned off and are only enabled on testing servers)...

Code: Select all

 
if ($result_1) {
  $category_photo = mysql_num_rows($result_1); 
}
 
Good luck! :)

Re: PHP 4.4.4 to 5.2.6 broke my site!

Posted: Sat Jul 12, 2008 7:42 pm
by jaoudestudios
I have just noticed possibly another issue, if my memory serves me correct in php5 you cant use php tag short cuts, so you will need to change any opening php tags ( <? ) to the full opening php tag ( <?php ).

Re: PHP 4.4.4 to 5.2.6 broke my site!

Posted: Sat Jul 12, 2008 8:01 pm
by jayman30
:mrgreen: YEAA HAAWWW!!!

Its up and running, THANKS A MILLION!!

That one line of code fixed and its back 100%!

Thanks again, :D :D :D

jayman30