Sourav
Sourav

Reputation: 17530

Do i need to convert an variable to Int when using Prepared Statement - PHP

$stmt = mysqli_prepare($con,"INSERT INTO friend_request (ToUID, FromUID) VALUES (?,?)");
mysqli_stmt_bind_param($stmt, "ii", $fid, $uid);
mysqli_stmt_execute($stmt);
if (mysqli_stmt_affected_rows($stmt))
  echo 'Request Sent';
else
  echo 'Something went wrong !';

In the above code i have written mysqli_stmt_bind_param($stmt, "ii", $fid, $uid);
Should i convert $fid = (int) $fid to make any improvement ?

Is there really any difference between [ the data type of ToUID,FromUID in database is int ] ?

mysqli_stmt_bind_param($stmt, "ii", $fid, $uid);  
mysqli_stmt_bind_param($stmt, "ss", $fid, $uid);

Upvotes: 1

Views: 80

Answers (1)

Alix Axel
Alix Axel

Reputation: 154633

No, and it's a good practice to let the database cast the values (as long has you have a good schema).

Upvotes: 2

Related Questions