Giter Site home page Giter Site logo

Correct data type about php-crud-api HOT 6 CLOSED

mevdschee avatar mevdschee commented on May 8, 2024
Correct data type

from php-crud-api.

Comments (6)

mevdschee avatar mevdschee commented on May 8, 2024

There is an easier way (than PDO), you can for instance see how I did this for binary data and nulls. But first, let's analyze the problem:

  • string, number, object, array, true, false, null are supported by JSON.
  • array, object, true, false are not supported by MySQL.
  • decimal, binary, date are not supported by JSON.
  • string, number, null are supported by both.
  • nulls and strings are handled "correctly".
  • PHP implicitly converts strings to numbers when needed.

I'm not saying there can not be a benefit. I think there could be two theoretical benefits in PHP receiving floats and ints (how about decimal type? BC Math?) from MySQL in their corresponding type:

  • Avoiding imprecision of string conversion (for floats)
  • Performance (no conversion, higher speed)

But do we actually achieve that when we would be receiving floats and ints from PDO? I wonder. Maybe you see other benefits?

from php-crud-api.

mevdschee avatar mevdschee commented on May 8, 2024

Maybe we should bypass PHP and output the MySQL string to javascript (JSON) directly. Still I'm worried about javascript's handling of MySQL types.

from php-crud-api.

mevdschee avatar mevdschee commented on May 8, 2024

I see no solution for longs and decimals, but a conservative change would be to output small to normal sized integer types without quotes.

from php-crud-api.

ManniManfred avatar ManniManfred commented on May 8, 2024

In my case it would be ok, because I currently need it only for integers.

from php-crud-api.

mevdschee avatar mevdschee commented on May 8, 2024

As you can read here only 53 bits of a 64 bit int are supported. So only 32 bit integers (or smaller) could go without quotes without losing precision.

from php-crud-api.

mevdschee avatar mevdschee commented on May 8, 2024

Fixed in 8616b67, but may cause issues on 8 byte integers (>53 bit) as they cannot be represented in JavaScript. See: 1fce372

from php-crud-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.