php mysql fetch row as int code example

Example: MySQL integer field is returned as string in PHP

When you select data from a MySQL database using PHP the datatype will always 
be converted to a string. You can convert it back to an integer using the 
following code:

1. $id = (int) $row['userid'];

2. For Laravel you can also use cast variable inside your model where you can 
   set them as integer.
   
   Example :  protected $casts = [
                  'default' => 'integer',
                  'phonecode' => 'integer',
              ];
    
############################ OR ######################################

The Other solution is from the server where you need to have access to change
your PHP extensions so inside that you just need to revert some extensions

mysql && mysqli && pdo_mysql

###################### TO ########################

mysqlnd && nd_mysql && nd_mysqli && nd_pdo_mysql

For more details regarding these extensions are mentioned here
https://cloudlinux.zendesk.com/hc/en-us/articles/115004347574-Missing-MySQL-extension-or-MySQL-ND-vs-MySQL-

Tags:

Php Example