Articles in the MySQL Category
MySQL, PHP »
Converting the datetime format is really simple if you let MySQL do the formatting for you.
MySQL 5.1 SELECT DATE_FORMAT manual
For instance, if you wanted to convert the datetime into something that reads
function ConvertNiceDateOnly($date)
{
// Convert mySQL date to nice formatted date
$normaldate = mysql_query("SELECT DATE_FORMAT('$date','%M %e, %Y')");
$normaldate = mysql_fetch_row($normaldate);
$normaldate = $normaldate[0];
return $normaldate;
}
MySQL, PHP »
$unixseconds = strtotime($mysqldate);
For instance, you can use this to write a timeout script for login failures. Usually, a system should lock after 3-5 consecutive failed login attempts. I save the timestamp after the 5th consecutive login failure, then run a check on this timestamp if the current time is within the ~5-10 minute lockout window. 5 minutes is 300 seconds, 10 minutes is 600 seconds.
MySQL »
I looked through the documentation on MySQL and it looks like they removed the “rename database” option. Here’s a workaround:
mysqladmin create [Name of new database]
mysqldump –opt [Name of old database] | mysql [Name of new database]
MySQL »
Here’s a quick reference to reset the MySQL auto_increment field to 1 and delete ALL rows in a table. This is useful in case you had to do some testing and wanted to reset the primary key field back to 1 and clear out the table.
truncate table [NAME OF TABLE]
If you don’t want to wipe out the table, you can reset the auto_increment by using:
alter table [NAME OF TABLE] auto_increment=1
