0

I have a lot of sql query on my php code, and all of them work well except this one.

$sql_pay = "SELECT * FROM transaccion_cobro WHERE codigo='A2131231' AND idEstadoTransaccion=2";
$query_pay=mysql_query($sql_pay,$db);
$num_pay = mysql_num_rows($query_pay);

This is the error I get:

mysql_num_rows() expects parameter 1 to be resource, boolean given

I guess that mysql_query fails and returns false. But I don't know why. If I execute that query on "MySQL Query Browser" it returns the expected values. Also, the rest of the queries are correctly executed.

Does anyone have any idea of what could be happening here?

UPDATE:

Problem solved thanks to @ICanHasCheezburger comment

Rumpelstinsk
  • 2,822
  • 3
  • 24
  • 53

2 Answers2

0

Try this

$sql_pay = "SELECT * FROM transaccion_cobro WHERE codigo='A2131231' AND idEstadoTransaccion=2";
$query_pay=mysql_query($sql_pay,$db);
if ( $query_pay ) {
    $num_pay = mysql_num_rows($query_pay);
} else {
    echo "Query Failed: " . mysql_error($db);
}

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

Have a look at this Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
zzlalani
  • 21,360
  • 16
  • 42
  • 72
-2

$query_pay=mysql_query($sql_pay,$db); Make it $query_pay=mysqli_query($db, $sql_pay); and $num_pay = mysql_num_rows($query_pay); Make it $num_pay = mysqli_num_rows($query_pay);

Then it should work because mysqli_query necessarily takes $db or connection parameter, for mysql_query it is optional.

Rolen Koh
  • 715
  • 2
  • 10
  • 20