Sometimes, we want to fix MySQL integer field is returned as string in PHP.
In this article, we’ll look at how to fix MySQL integer field is returned as string in PHP.
How to fix MySQL integer field is returned as string in PHP?
To fix MySQL integer field is returned as string in PHP, we can convert it to an integer with int
or intval
.
For instance, we write
$id = (int) $row["user_id"];
or
$id = intval($row["user_id"]);
to cast $row["user_id"]
with (int)
or convert $row["user_id"]
to an integer with the intval
function.
Conclusion
To fix MySQL integer field is returned as string in PHP, we can convert it to an integer with int
or intval
.