database returning string value for integer columns

Solutions on MaxInterview for database returning string value for integer columns by the best coders in the world

showing results for - "database returning string value for integer columns"
Adèle
16 Aug 2018
1When you select data from a MySQL database using PHP the datatype will always 
2be converted to a string. You can convert it back to an integer using the 
3following code:
4
51. $id = (int) $row['userid'];
6
72. For Laravel you can also use cast variable inside your model where you can 
8   set them as integer.
9   
10   Example :  protected $casts = [
11                  'default' => 'integer',
12                  'phonecode' => 'integer',
13              ];
14    
15############################ OR ######################################
16
17The Other solution is from the server where you need to have access to change
18your PHP extensions so inside that you just need to revert some extensions
19
20mysql && mysqli && pdo_mysql
21
22###################### TO ########################
23
24mysqlnd && nd_mysql && nd_mysqli && nd_pdo_mysql
25
26For more details regarding these extensions are mentioned here
27https://cloudlinux.zendesk.com/hc/en-us/articles/115004347574-Missing-MySQL-extension-or-MySQL-ND-vs-MySQL-
28