Archive for the 'mysql' Category

Random MySQL date

Jan 29th, 2009

Random date/time Need to generate a random date in MySQL? Here: mysql> SELECT FROM_UNIXTIME(RAND() * 2147483647) AS `rand`; +———————+ | rand | +———————+ | 1998-04-01 21:42:48 | +———————+ 1 row in set (0.00 sec) Let’s try once again and get a different random value: mysql> SELECT FROM_UNIXTIME(RAND() * 2147483647) AS `rand`; +———————+ | rand | […]


Reusing an existing database connection with MDB2

Jan 4th, 2007

This is a follow up to a question posted by Sam in my DB-2-MDB2 post. The question was if you can reuse an exisitng database connection you’ve already established and not have MDB2 creating a second connection.


MySQL Events scenario (and a funky subquery)

Dec 15th, 2006

Coming back to those MySQL events with a sort of more practical example. In case you’ve missed the previous post, events in brief: turns out that in MySQL starting from 5.1.6. you can setup and schedule cronjobs in the DB server itself. These are called events. An intro article and MySQL manual entry. What these […]


MySQL events

Dec 14th, 2006

The journey “Fall in love with MySQL (again)” continues from here (triggers) and here (views). Next stop – MySQL events. A cold shower first – events are not available in versions < 5.1.6. so chances of using them any time soon are pretty slim. You need to upgrade to 5.1. (beta) if you want to […]


MySQL Views

Dec 11th, 2006

Continuing (from here) the “Discover MySQL’s enterprise features” trip, let’s check out the Views. As the name suggests, a view is like a specific predefined way to look at a table or tables. You can create a View out of one table or you can JOIN a few tables. Back to the `blog` database example. […]


Quick MySQL 5 penetration survey

Dec 10th, 2006

In a previous post about the MySQL triggers, I mentioned that inexpensive web hosts are now offering MySQL 5. This was based on ICDsoft’s hosting plan, this is a (highly recommended, awesome support!) company I’ve been using for years and I was thinking that it represents the avegarge $50-60/year web hosting solutions offered worldwide, which […]


Performance tuning with MDB2

Dec 9th, 2006

This is a follow-up to Lars’ comment about the PEAR book. In the MDB2 chapter I showed an example how you can create custom debug handlers in MDB2 and then gave a suggestion about a useful application of this functionality for performance tuning. Basically the idea is that your custom debug handler collects all queries […]


MySQL triggers

Dec 8th, 2006

Now that even my favourite $50/year web hosts (example) are offering MySQL 5 and even recommending it over 4, why not take advantage of MySQL’s “enterprise” features. Like triggers. OK, what’s a trigger? It’s something that happens as a result of something else. Clear? Yeah, maybe an example. Say, as it often happens in life, […]


Enumerating with MySQL

May 15th, 2006

Here’s how I got MySQL to do some enumerating for me, meaning increment a counter and add it to a select statement as in a numbered list. It is questionable if this type of functionality should be part of the “business” logic, as opposed to the display logic, but still, you never know. What you […]



Feb 4th, 2006

Recently I had to move an existing project from using PEAR::DB to PEAR::MDB2 – the new database abstraction layer. I took notes on the parts of the code I needed to change, I hope they can benefit someone who’s doing the same.