Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MaxDB - Everything about MaxDB, formerly known as SAP DB
MySQL++ - Programming with the C++ API to MySQL
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
ODBC - ODBC with the MySQL Connector/ODBC driver
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
help with storing a large binary number as bigint

help with storing a large binary number as bigint

2006-06-02       - By Jeremy Cole

 Back
Reply:     1     2     3  

Hi Byron,

>  This should be a relatively simple question but after looking through
> the manual for a while I didn't see how to do it. I am working in php
> and need to store a large binary number in the database. When I try and
> convert it to a int in php its too big so it converts it to a float and
> I loose all all precision witch makes it worthless to me. Is there a way
> to let mysql do the conversion since the number I am working with is
> 48bits and bigint can store 63bits??? I would need to be able to insert
> and select it as a binary string?

Yes, you can do this.  Probably the best way to do this is to insert it
as a hexadecimal number.

Is the binary string in big or little endian form?

If it's big endian, you can convert it directly to hex with bin2hex(),
prefix it with 0x, and insert it as:

INSERT INTO mytable (x, y, ...) VALUES (0x123456, 0x654321);

If it's in little-endian format, you will need to do the byte-swapping
before/after the bin2hex.  (In pure PHP, it might be easier after.)

Regards,

Jeremy

--
Jeremy Cole
MySQL Geek, Yahoo! Inc.
Desk: 408 349 5104

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@(protected)