0

Using the PHP PDO library, I'm trying to use a prepared statement, but it's not working. I have this sql:

$update_sql = "UPDATE test_table SET zero_or_one_photo = 1 WHERE mls_id = :mls_id AND mls_no in ( :mls_no_list )";
$update_stmt = $dbh->prepare($update_sql);

I bind the values:

$update_stmt->bindValue( ':mls_id', 'MD-BRIGHT' );
$update_stmt->bindValue( ':mls_no_list', '1234567' );

(eventually, I will have many values for the mls_no, but I'm just testing now)

$rows = $update_stmt->execute();
print "Execute returns: $rows rows\n";

this writes out "Execute returns 1 rows", but the database value is not actually changed. If I change things slightly:

 $update_sql = "UPDATE test_table SET zero_or_one_photo = 1 WHERE mls_id = :mls_id AND mls_no in ( '1234567' )";
 $update_stmt = $dbh->prepare($update_sql);

I bind just the one value:

$update_stmt->bindValue( ':mls_id', 'MD-BRIGHT' );
$rows = $update_stmt->execute();
print "Execute returns: $rows rows\n";

Also writes out that 1 row was changed, but this time, the database row actually did change. Is this just the way it is - you can't bind into an "IN ()" clause?

Andy Wallace
  • 299
  • 5
  • 20
  • That's an interesting idea - I normally shy away from ? parameters for clarity, but that should work, I think. Let me try that... – Andy Wallace Aug 12 '21 at 21:23
  • Here's some [other ideas](https://phpdelusions.net/pdo#in) if it may be helpful. (similar ideas, different handling) – Paul T. Aug 13 '21 at 02:41

0 Answers0