Answers for "php use mysqli field as string"

SQL
0

database returning string value for integer columns

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-
Posted by: Guest on November-20-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language