-1

A simple question,

Why PHP fetch() transform INT into STRING ?

Example :

  • DATABASE structure : is_active int(11)
  • PHP fetch : 'is_active' => string '1' (length=1)
Vimal
  • 1,140
  • 1
  • 12
  • 26
Azee
  • 71
  • 12
  • Not a duplicate, my question is why ? Not answerred in this post – Azee Apr 07 '17 at 07:35
  • Yes, it's answered here: http://stackoverflow.com/a/5323169/916000 – Taha Paksu Apr 07 '17 at 07:47
  • The real answer to 'why' is probably hidden in the depths of mysql plugin development. Perhaps an oversight, perhaps a shortcut that was never fixed. There is most likely no intent behind this behavior. – glaux Apr 07 '17 at 08:27
  • Sorry for double comment about duplicates, I didn't use the correct flag the first time and just typed it manually. – glaux Apr 07 '17 at 08:28
  • I voted to close this as a duplicate of http://stackoverflow.com/questions/13617436/mysqli-fetch-assoc-pdo-fetch-assoc-storing-numbers-as-strings/13617509#13617509 in which I give the answer of *why*: because PHP has no support for unsigned integers. – Bill Karwin Apr 10 '17 at 00:47

1 Answers1

0

In my opinion, it's for Trading off some of the performance and accessibility.

In short, if mysql uses only one-type(string) data, containers may have one-type tuple and does not need complex data structure.

  1. There are various datatypes for various database.

For example, int is easy data-type. but there are int32, int64, unsigned int and every-databases has its own data-type, php could simplify what type is it. ie. we cannot simple say that varchar2 could be converted with string since there are text, varchar, varchar2, string.

  1. Easy for Beginners

In my opinion, The advantage of php is that it is easy for beginners to use. If PHP took type from database. It would have object such as DBResult { enum datatype, Object DataSet }

it seems complex and increase the size of the code.

  1. Flexablity: It can actually handle everything

String can contain every datatype except binary(blob) format.!

Thank you.

Kwang-Chun Kang
  • 351
  • 3
  • 12