Error on large MySQL imports on a WAMP stack…

Error: [text]Got a packet bigger than ‘max_allowed_packet’ bytes[/text] Fix: 1. Open my.ini from your MySQL installation directory, add this line to the [mysqld] section: [text]max_allowed_packet = 100M[/text] (The value (100M) is arbitrary – use whatever.) 2. Restart MySQL (easiest way IMO is Start > Control Panel > Administrative Tools > Services… right-click ‘mysql’ service and […]

MySQL – get random row

select * from table_name order by rand() limit 1

MySQL – get next / previous record

assuming you’re using an auto-incremented PK called ‘id’, compared to a bound param ‘:id’ which represents the current record… next: select id from table where id > :id order by id limit 1; previous: select id from table where id < :id order by id desc limit 1;

Getting Progress (bytesLoaded, bytesTotal) from dynamic XML

Seldom do I use straight XML files anymore; they always seem to be generated from dynamic content, often from PHP running through a DB table.  By dynamically generating the XML file, the system has no way of knowing the size of the final output, so ProgressEvent.PROGRESS listeners will silently fail.  It’s easy enough to remedy […]

MySQL – find longest string in column

this comes in handy with surprising frequency get the length of the longest string in a column select max(char_length(COLUMN_NAME)) from TABLE_NAME select the longest string in a column select COLUMN_NAME from TABLE_NAME where char_length(COLUMN_NAME) = (select max(char_length(COLUMN_NAME)) from TABLE_NAME)

MySQL – Find and Replace in Table

update set = replace(, “”, “”) where like ‘%%’ the where clause isn’t technically necessary, but i’d guess it’d be more efficient (not tested). an example without illustrative characters: update users set username = replace(username, “bob”, “ken”) where username like ‘%bob%’