私はphpを使用しており、mysqlサーバーでSQLクエリを実行しています。SQLインジェクションを防ぐために、私はmysql_real_escape_stringを使用しています。
また、次のように、数値のキャストに(int)を使用しています。
$desired_age = 12;
$query = "select id from users where (age > ".(int)$desired_age.")";
$result = mysql_query($query);
その仕事。
ただし、変数に大きな数値が含まれている場合、それらはintよりも大きいため、キャストは失敗します。
$user_id = 5633847511239487;
$query = "select age from users where (id = ".(int)$user_id.")";
$result = mysql_query($query);
// this will not produce the desired result,
// since the user_id is actually being cast to int
SQLインジェクションの防止に関しては、mysql_real_escape_stringの使用を除いて、多数をキャストする別の方法(BIGINTなど)はありますか?