PHP ile pg_query_params dönüş değerini kontrol

2 Cevap php

How can you check if a resource is false in PHP`s pg query params

Ben başarısız aşağıdaki kodu çalıştırın

 $row = pg_num_rows ( $result );
 if ( $row !== 0 )
        echo "hurray";
 else
        echo "argh";

Bana aşağıdaki uyarıları verir

Warning: pg_query_params() [function.pg-query-params]: Query failed: ERROR: invalid input syntax for integer: "" in /var/www/codes/index.php on line 120

I use $dbconn which is correct so the the second warning seems to be only a sympton. The cause of this is the invalid type for an integer.

Benim sorgu bu

$dbconn = pg_connect("host=localhost port=5432 dbname=masi user=masi password=123");
$result = pg_query_params ( $dbconn,
    'SELECT question_id
    FROM questions
    WHERE question_id = $1',
    array ( $question_id )
);

2 Cevap

Bu deneyin:

$result = @pg_query_params($dbconn, "SELECT * FROM SOME_TABLE", array());
if($result !== FALSE)
{
  $row = @pg_num_rows($result);
  if ( $row !== 0 )
         echo "hurray";
  else
         echo "argh";
}
else
{
  echo "Seems, your query is bad.";
}

Eğer $ sonuç kullanmadan önce, bunu kontrol gerekir.

Eğer "NULL sorgu" derken ben herhangi bir sonuç satırlarını etkilemez ya da döndürmeyen bir sorgu demek olduğunu varsayalım.

Herhangi başarılı bir sorgu her zaman satırlar etkilenmiş olsun veya olmasın / döndü, her zaman doğru olacak, geçerli bir sorgu sonuç kaynak neden olacaktır. Sorgu başarıyla pg_affected_rows (UPDATE / INSERT / DELETE) veya pg_num_rows (SEÇ) ya da kullanmak zorunda bir veya daha fazla satır uygulanmış olup olmadığını görmek için.