0

I am already programing for many year already now i faced a real strange issue I have query which verify for duplicate id and tid

$query4=mysql_query("select id,tid from transactionlog  where     id='$result1[id]' and tid ='$result1[tid ]'")  ;

$num=mysql_num_rows($query4);
if ($num == 0)
{
// case new . insert new raw here
}

The db i am using is fairly big over 500k raw , now the strange part is that this query sometime return num_rows 0 even when id and tid exist , this happen in about 1 time each few million queries , by the way i am using 5.6.35-log under windows (i need mysql old_password function that's why i am using older version ). I know it is possible to setup id and tx as primary and unique , but i really want to know how come num_rows returning 0 while it should have 1 . is it know bug that i am missing ?

anyone faced similar issue ???

  • 2
    `echo $query4;` – Strawberry May 13 '17 at 20:51
  • What type is `$result1`? Statement `id='$result1[id]'` looks strange... – Bor Laze May 13 '17 at 20:55
  • 1
    Please be aware that [`mysql_*()` functions are long deprecated](http://stackoverflow.com/q/12859942/2298301), and as such, the current code would gleefully accept all [SQL Injection Attacks](http://stackoverflow.com/q/60174/2298301). Please consider rewriting the code using [mysqli_*()](http://php.net/manual/en/mysqli.prepare.php) or [PDO](http://php.net/manual/en/pdo.prepare.php) _Prepared Statements_. Also, as suggested in the first comment, `echo`-ing the query to debug what it contains could reveal quite a few things about why it doesn't return the expected results. – Dhruv Saxena May 13 '17 at 21:42
  • It is probably a bug, just not in mysql, but in your code. Either you run into the known parallel insert problem (same id - tid pair being inserted at the same time) orsg goes wrong with your parameters. You need to log the queries to find it out, we will not be able to do that based on your code alone. – Shadow May 14 '17 at 00:04
  • There is no possible parallel insertion , since inserting raw is made by only one script running once each 5 min . Yes i logged the query , the num_result return 0 . – John Latez May 14 '17 at 21:56

0 Answers0