Search code examples
phpmysqltelephonyinteger-overflow

Telephone number changed to 2147483647? How to represent telephone numbers?


So, I've created a datatable that asks for a users Mobile Provider (varchar), phonenumber, and pin. The table seems to work well except that when a user inputs a phone number the original number converts to 2147483647. I've spent sometime looking around and I learned that this is because I've gone beyond the 32-bit limit on my table. In order to fix this, I need to make my integer limit larger than 10 (what I originally had) in MYSQL database.

I've changed the MYSQL table using PhpMyAdmin; however, I am still getting the same problem. Is this because I need to now change something on the Yii-end?

I know that I could use CRUD to contstruct a new MVC relationship - but I've already added in quite a few functions to the Model and the Controller. Is there a way with Yii to change my database in piecemeal way? I.e. without having to use Crud?


Solution

  • The fact that telephone directory numbers (DNs) resemble integers notwithstanding, using a integer of any width to store a DN is very bad practice indeed.

    That's because, as you have discovered, DNs that get manipulated as if they were integers sometimes become corrupted.

    Using a 32-bit number to store a North American Dialing Plan number (Canada, Caribbean, US) is just flat incorrect. Partway through the 429 area code, your numbers will be corrupted even if you manage to use an unsigned integer.

    Use varchar(20) and you'll be fine.

    Here's something to think about: ITU-T recommendation E.123 for representing telephone numbers. http://en.wikipedia.org/wiki/E.123