MySQL

Time and Date functions

Fred's picture

Drupal stores time information (such as created date, modified date, etc) in unix date format as int(11).
Using a simple statement:

SELECT n.`created` FROM node n

1225678626

FROM_UNIXTIME()

Formats the data as date & time:

SELECT FROM_UNIXTIME(n.created) FROM node n

2008-11-03 02:17:04

DATE()

Just the date:

SELECT DATE(FROM_UNIXTIME(n.created))  FROM node n

2008-11-03

Zen Cart

Fred's picture

Zen Cart is a very popular shopping cart system forked from oscommerce. While the Zen Cart homepage claims that it is easy to install, configure and use, sometimes the method of changing options and features can be a little confusing. Whatever you do, don't get me started on their theming - it's not pretty.

Copy structure and data from one table to another (including database to database)

Fred's picture

Sometimes you need to copy a table from one database to another. itmay be that you need o take a backup before messing around with the structure, or to copy information from a live database to a development database. Initially I thought the following would do the trick:

DROP TABLE IF EXISTS target_db.target_table;
CREATE TABLE target_db.target_table SELECT * FROM source_db.source_table;

This does the following:

MySQL Goodies

Fred's picture

MySQL is a great alternative to Microsoft's SQL Server. Yes, it does have it's downsides, but for a lot of people and organisations both large and small, it is more than sufficient for their needs and doesn't cost an obscene amount of money. Before any of you go on about PostgreSQL, I am fully aware of it, but it's support under Drupal leaves a lot to be desired.

Anyway, useful snippets, tips and tricks abound, hopefully some will be of use to you!

Syndicate content