Archive for the ‘MySQL’ Category

h1

A nice way to check if there are orphaned entries

September 5, 2007

In a database table that is linked to another, sometimes an entry gets deleted and the children of that entry don’t get deleted along with it. Use this little bit of SQL to check for these entries:
SELECT one.id
FROM one
WHERE one.other_id NOT IN (
SELECT other.id
FROM other);

This can then be modified to delete those entries by changing the SELECT one.id to DELETE, like this:
DELETE
FROM one
WHERE one.other_id NOT IN (
SELECT other.id
FROM other);

h1

Debugging and benchmarking MySQL in PHP

August 27, 2007

I stumbled across this link on my travels and it helped quite a bit in sriting some small piece of benchmarking MySQL with PHP. I took the code and replaced it into my own script that wrote to a database and then read from it. It needed one small change to make it work for me, I needed to add in:
$res = array();

Here is the link:
http://3rdmover.com/mysql-debugging-in-php

h1

Why ‘created’ and ‘modified’ fields might not save

May 28, 2007

https://trac.cakephp.org/ticket/2595

I found this when I was searching for a reason that the created and modified fields were not automagically saving when I saved a record to the database.

What is says is that instead of defining the created and modified fields as NOT NULL, they should be defined as NULL and let Cake then go ahead and put an entry into them. This is for version 1.2

Use
`modified` datetime default NULL,
instead of
`modified` datetime default NOT NULL default '0000-00-00 00:00:00',