0

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)
5
  • Not a duplicate, my question is why ? Not answerred in this post Commented Apr 7, 2017 at 7:35
  • Yes, it's answered here: stackoverflow.com/a/5323169/916000 Commented Apr 7, 2017 at 7: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. Commented Apr 7, 2017 at 8:27
  • Sorry for double comment about duplicates, I didn't use the correct flag the first time and just typed it manually. Commented Apr 7, 2017 at 8:28
  • I voted to close this as a duplicate of stackoverflow.com/questions/13617436/… in which I give the answer of why: because PHP has no support for unsigned integers. Commented Apr 10, 2017 at 0:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.