June 19, 2013

Post: Integers in PHP, running with scissors, and portability

…. Oh wait, no – that’s on 32-bit platforms only! PHP int size is platform-dependent, and it seems to be 8… ) { // on x64, we can just use int if ( ((int)4294967296)!=0 ) return (((int)$hi)<<32) + ((int)$lo); // workaround signed/unsigned braindamage on x32 $hi = sprintf… C/C++ snippet look like: typedef unsigned long long myuint64; // just for brevity unsigned int a = 0xffffffffULL; unsigned int b = 0xffffffffULL; myuint64 c = (myuint64(a…

Post: PHP vs. BIGINT vs. float conversion caveat

….0: s1=1125899906842625 s2=1125899906842625 However 32-bit FreeBSD with PHP 4.4.7 produces different results: s1=1.1258999068426E+15… and PHP versions. So if you’re handling large numbers stored as float (especially on 32-bit systems where 32-bit int… it comes to fixing PHP “subtleties” in numeric value handling: it can be used to workaround signed vs. unsigned int issues; it helps…

Comment: Integers in PHP, running with scissors, and portability

… the usual value (that’s 32 bits signed). PHP does not support unsigned integers.” You will also run into problems when doing…. For example, try on php -r “var_dump(unserialize(‘i:234444444444444344;’));” It will return either int(234444444444444344) or int(-424884552) depending on architecture…

Comment: Why MySQL could be slow with large tables ?

… currently working on a web project using MySql, Apache and Php. The database has a relatively acceptable size, not only in… ( A INT(10) UNSIGNED NOT NULL, B INT(10) UNSIGNED NOT NULL, C TINYINT(3) UNSIGNED NOT NULL DEFAULT ’0′, D TINYINT(3) UNSIGNED NOT NULL DEFAULT ’1′, E TINYINT(3) UNSIGNED

Post: GROUP_CONCAT useful GROUP BY extension

…? For example to get PHP array without looping inside PHP: Table: CREATE TABLE services ( id INT UNSIGNED NOT NULL, client_id INT UNSIGNED NOT NULL, KEY… | GROUP_CONCAT(client_id) | +—-+————————-+ | 3 | 5,6,7 | +—-+————————-+ Handling in PHP: old way: with group_concat: This should work faster, as…

Comment: Multiple column index vs multiple indexes

… set utf8 default NULL, `state` varchar(2) default NULL, `zip` int(5) unsigned NOT NULL, `country` varchar(20) default NULL, `website` varchar…` varchar(50) default NULL, `sic` int(10) unsigned default NULL, `sic_des` varchar(100) default NULL, `uid` int(10) default NULL, PRIMARY KEY…,95055,95056)) order by dis LIMIT 0, 10 i use php(v5.2) to connect to mysql(v5.02) but it…

Post: MySQL automatic data truncation can backfire

… problem I found out PHP and MySQL are both to blame. PHP is to blame because in 32bit PHP version result of crc32… of same PHP version it became signed. The system worked on 32bit platform initially so “key” column was defined as “int” As it was migrated to 64bit platform we got unsigned 32bit values which did not fit…

Comment: GROUP_CONCAT useful GROUP BY extension

GROUP_CONCAT in MySQL… GROUP_CONCAT(expr) – This function returns a string result with the concatenated non-NULL values from a group. Where it can be useful? For example to get PHP array without looping inside PHP: CREATE TABLE services ( id INT UNSIGNED NOT NULL, client_id …