Zen Cart Logo
Forums / Code Collaboration / mysql_num_rows error

mysql_num_rows error

Views: 12,502

Results 1 to 3 of 3
5 Feb 2016, 11:39 PM
#1
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

mysql_num_rows error

As I'm in the process of upgrading to 1.5.4 on a server running PHP 5.6 this

if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".DB_PREFIX."so_payment_types'"))){
    $sql = "TRUNCATE TABLE ".DB_PREFIX."so_payment_types";
    $db->Execute($sql);
}
```  (which is Super_orders' init_so_config.php) fire me with

> PHP Warning:  mysql_num_rows() expects parameter 1 to be resource, boolean given in /ADMIN/includes/init_includes/init_so_config.php on line 13.

Would this replacement work and is it the write syntax ?

$sql = "SHOW TABLES LIKE '".DB_PREFIX."so_payment_types'";
$result = $db->Execute($sql);
$row_cnt = $result->num_rows;
if($row_cnt){
$sql = "TRUNCATE TABLE ".DB_PREFIX."so_payment_types";
$db->Execute($sql);
}


Thanks for your help

Hubert
6 Feb 2016, 2:27 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: mysql_num_rows error

hubert:

As I'm in the process of upgrading to 1.5.4 on a server running PHP 5.6 this

if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".DB_PREFIX."so_payment_types'"))){
$sql = "TRUNCATE TABLE ".DB_PREFIX."so_payment_types";
$db->Execute($sql);
}

> 
> .
> 
> Would this replacement work and is it the write syntax ?
> 
> ```
$sql = "SHOW TABLES LIKE '".DB_PREFIX."so_payment_types'";
    $result = $db->Execute($sql);
    $row_cnt = $result->num_rows;
    if($row_cnt){
    $sql = "TRUNCATE TABLE ".DB_PREFIX."so_payment_types";
    $db->Execute($sql);
}

Thanks for your help

Hubert

No, it would not, also if you were to look at the forum thread for the plugin then would see that there is/should be a version available that is compatible to 1.5.4 simplifying your effort... and really? this code doesn't use a table define but instead the table format from below? Wow, didn't realize it needed that kind of upgrading...

a rewrite of this could be:

    $sql = "SHOW TABLES LIKE '".DB_PREFIX."so_payment_types'";
    $result = $db->Execute($sql);
    $row_cnt = $result->RecordCount();
    if(!$result->EOF && $row_cnt > 0){
      $sql = "TRUNCATE TABLE ".DB_PREFIX."so_payment_types";
      $db->Execute($sql);
    }

That is if $row_cnt is used further below... If not then it could be reduced to something like:

    $sql = "SHOW TABLES LIKE '".DB_PREFIX."so_payment_types'";
    $result = $db->Execute($sql);
    if(!$result->EOF && $result->RecordCount() > 0){
      $sql = "TRUNCATE TABLE ".DB_PREFIX."so_payment_types";
      $db->Execute($sql);
    }

But there probably is another way that it has been incorporated or otherwise done... Again, suggest looking at the work that has already been done which will also simplify future upgrades...

6 Feb 2016, 11:14 AM
#3
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Re: mysql_num_rows error

Thank you very much mc12345678.

I had made a search on the forum for this function but I didn't find anything usefull in the answers.
Now that I've read the support thread, you're right, I'm not the first one to face this.

Thanks again for your code advices it helps me understand things

Hubert