PHP-MySQLi bind_params() int or string?

When using the mysqli_bind_params() function, you may want to consider listing int parameters as strings if the number may be greater than the maximum allowed value for an int.

For Example:

If you specify type “i” (integer), the maximum value it allows you to have is 2^32-1 or 2147483647. So, if you are using UNSIGNED INTEGER or BIGINT in your database, then you are better off using “s” (string) for this.

Here’s a quick summary:

(un)signed TINYINT: i
(un)signed SMALLINT: i
(un)signed MEDIUMINT: i
signed INT: i
unsigned INT: s
(un)signed BIGINT: s

(VAR)CHAR, (TINY/SMALL/MEDIUM/BIG)TEXT/BLOB should all have “s”.

FLOAT/REAL/DOUBLE (PRECISION) should all be “d”.

So when you call your dbUpdate function, the following is correct for the initial 2billion records, but would lead to problems after that:

dbUpdate( $query, array("i", $bigIntValue) );

This is how it should be done:

dbUpdate( $query, array("s", $bigIntValue) );

This advice is for MySQL Databases.

Leave a Reply

Your email address will not be published. Required fields are marked *