String equality comparisons are much more expensive than integer compares. If a database value is an integer, it MUST NOT be treated as a numeric string. This holds especially true for primary keys and foreign keys.

Incorrect:


$sql = "
    UPDATE sc_addresses
    SET customer_id = '" . (int)$customer_id . "'
    WHERE address_id = '" . (int)$address_id . "'";


UPDATE sc_addresses
   SET customer_id = '54321'
 WHERE address_id  = '67890';


Correct:

$sql = '
    UPDATE sc_addresses
    SET customer_id = ' . (int)$customer_id . '
    WHERE address_id = ' . (int)$address_id;


UPDATE sc_addresses
   SET customer_id = 54321
 WHERE address_id  = 67890;