Bigint issue when will be displayed at template - php

I have a MySQL database with a bigint field but when I'm using on cakephp the number 697483533702444 is being displayed as 2147483647

You need to either use a 64bit version of PHP or store your data in the database as a CHAR(20) or VARCHAR(20)

I cant write comment (missing points), but I experienced some Problems with signed and unsigned Integers and quite similar results. Please try changing signed and unsigned in the database.

Related

Mysql Error 1071 Specified Key value is too Long

I'm using my Web Application in Godaddy Hosting Server. Php Version is 7.1 and mysql Version is 5.6
while i'm trying
ALTER TABLE aos_products_quotes
modify COLUMN discount varchar(255) DEFAULT 'Percentage' NULL ,
modify COLUMN parent_type varchar(255) NULL ,
modify COLUMN parent_id char(255) NULL ;
these query in my domain sql server its shows
MYSQL #1071 Error Specified Key value is too long
I think i need to use mysql 5.7 or else need to set the global prefix variable is 1..But the Global setting need super privileges..At Godaddy side they told its impossible on Shared hosting..
I try my best about that issue so anyone guide me to solve that issue..
Thanks in advance...
There are many options to fix this:
You can try by changing the character set of columns so that they
use less bytes in storage.
You can change / remove indexing of the table. May be you are using
composite index whose limit is reached after this alteration.
Try less length of varchar() columns.
share the complete table structure to help you better.
Thanks

PHP mysql bigint issue

I have two tables with bigint:
table1
id bigint(20) PK autoincrement
name varchar(40),
text
table2
id bigint(20) PK autoincrement
created datetime
text_field
id_table1_ref bigint(20)
After inserting data into table1 and trying to insert table1.id into table2.id_table1_ref,
the number is different, i.e.:
Number 1552545662588 from table1.t1 becomes 1552545662, or even worse, a negative number.
I know this is an issue with settings, but I can't figure out how to manage this.
I tried to set up signed/unasigned values for the fields, but it doesn't work.
This is happening on my UNIX local computer, on the server all is working ok, at least for now.
Any help would be much appreciated.
You need to CONVERT it to a string in SQL before getting it into PHP. In PHP, you can use GMP to handle the number.
MySQL docs on converting: http://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
It's also the case that PHP under at least some 64-bit operating systems (eg FreeBSD AMD64) uses an 8-byte int, verifiable by testing with
echo 'Size of int is '.PHP_INT_SIZE ;
So if you're only going to be running a 64-bit operating system, you shouldn't need to manage the BIGINTs as strings in PHP.
I solved this problem by change to another php version,that is changing from 64bit php version to 32bit php version. That really works for me.

How do I store a BIGINT in MySQL using PDO?

I know this question has been asked more than once here, but I couldn't find a solution.
We are using a database where we are storing the facebook id as a BIGINT(20).
create table users(
fb_id bigint(20) NOT NULL,
user_name varchar(30) NOT NULL,
CONSTRAINT uk_name unique (user_name),
CONSTRAINT pk_fb_id primary key (fb_id)
)ENGINE=INNODB;
But the PDO engine of PHP can insert only the max integer value of PHP, i.e. 2147483647.
$stmt->bindParam(':fb_id', $this->fb_id, PDO::PARAM_INT);
This, I understand, is quite obvious since we are limited by the maximum value of integer in PHP. I tried to use the string -
$stmt->bindParam(':fb_id', $this->fb_id, PDO::PARAM_STR);
but still it doesn't work.
I want to know if there could be a workaround to store it as bigint.
We are using a database where we are storing the facebook id as a BIGINT(20).
Why oh why are you doing that?
I think general consensus is that Facebook ids should not be saved as numeric types, but as strings instead. Saving them as something numeric does not yield any advantages whatsoever – but several disadvantages.

SQLite syntax not compatible with MySQL?

I'm using PDO and trying to make my application support both MySQL and SQLite, but in sqlite I get this error when I try to import my database schema:
SQLSTATE[HY000]: General error: 1 near "AUTO_INCREMENT": syntax error
The query looks like this:
CREATE TABLE events (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL,
title VARCHAR(64) NOT NULL,
description LONGTEXT,
starttime DATETIME DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(id),
KEY name(name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(and it works in a MySQL database.)
I don't understand what the problem is here? Shouldn't both database systems be compatible?
http://www.sqlite.org/autoinc.html
In SQLite it's called AUTOINCREMENT, not AUTO_INCREMENT
They should be compatible as regards the ANSI SQL standards, and all SQL databases should adhere to that. However, AutoIncrement is not a part of that standard, but an extra feature implemented by some databases (including MySQL). Not all databases provide that feature, or may provide it in a different manner, or with different syntax.
AUTO_INCREMENT is MySQL-specific. SQLite apparently has a similar thing, AUTOINCREMENT.
Unfortunately though SQL should be a standard, each database implementation is different and have its own peculiarities, so you have to arrange your Query to make it work on SQLite.
No, they support a completely different set of features. The most significant difference is that SQLite uses dynamic data types whereas MySQL uses static data types, but there are many other differences too.
They do however both support a common subset of SQL, so it is possible to write some simple SQL statements that will work in both systems.

How to handle Facebooks new UID sizes?

I've been working a little bit on a Facebook application, but when I registered a new user to test the friend interaction the new user got a uid (100000XXXXXXXXX) that seems to big for php to handle.
Saving the number in the database results in the same value (2147483647). I'm guessing this is also PHPs fault, as I would believe the uid would fit in an unsigned bigint?
I'm not quite sure where to go from here, any suggestions?
The fix is to store the UID as a string always. Use the VARCHAR field type in MySQL and you will be fine.
In general, many database gurus will tell you that interpreting another application's foreign keys (like UID in this case) is bad bad bad and you should handle them as opaque text.
Facebook recommonds to store it as a BIGINT unsigned.
User object details and connections can be found here.
For PHP, you'd store it as a string (because, ultimately, if you're going to use it, it's going to be displayed on the page or in JSON data or something else that's stringy. There's no real need to perform arithmetic on that number).
I'm using BIGINT UNSIGNED for a couple applications and it works just fine.
What type of MySQL field are you storing the UID data in? An unsigned bigint can store up to 18446744073709551615. (See http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html)
Simply update your schema via something like...
ALTER TABLE <table name> MODIFY COLUMN <column name> BIGINT UNSIGNED NOT NULL;
...and I suspect all will be well.
NB: You'll want to try this on a backup to ensure I'm not deeply incorrect. :-)

Categories