Monthly Archives: September 2012

MAMP MySQL cannot access

Some important notes for root password change for MAMP

To change root password to empty/blank again, open terminal and type
/Applications/MAMP/Library/bin/mysqladmin -u root -p’root’ password ”
(root is the original password for mysql in mamp)

MAMP page
In: /Applications/MAMP/bin/mamp/index.php
Change to: $link = @mysql_connect(‘:/Applications/MAMP/tmp/mysql/mysql.sock’, ‘root’, ‘newpassword’);

PHPMyAdmin
In: /Applications/MAMP/bin/phpMyAdmin/config.inc.php
Change to: $cfg[‘Servers’][$i][‘password’] = root

PHP automatic run without cron job

If you don’t have a cron in your serveer, you can use this script to run a daily cron job.

Prepare a writeable file with a date inside and name it as ‘crondate.php’. The file should contain only date in one line.

2012-09-22

Run this function in a file on your website. It will check whether today’s date and date in file are different.
If yes, then it will call any function you want to run daily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function cron_daily_check() {
	//read file to get last date
	$filename = 'crondate.php';
	$handle = fopen($filename, 'r');
	$filedate = fgets($handle);
 
	//if date different, run a function and update file date
	if (date('Y-m-d') != $filedate) {	 
		/***** call any function or script to execute here ****/
 
		//write new date
		$fh = fopen($filename, 'w') or die("Failed to open file.");
		$stringData = date('Y-m-d');
		fwrite($fh, $stringData);
		fclose($fh);
	}		
}

Should we store datetime or unix timestamp in MySQL?

Timestamps in MySQL generally used to track changes to records, and are updated every time the record is changed. If you want to store a specific value you should use a datetime field.

If you meant that you want to decide between using a UNIX timestamp or a native MySQL datetime field, go with the native format. You can do calculations within MySQL that way ("SELECT DATE_ADD(my_datetime, INTERVAL 1 DAY)") and it is simple to change the format of the value to a UNIX timestamp ("SELECT UNIX_TIMESTAMP(my_datetime)") when you query the record if you want to operate on it with PHP.

Timestamp (both PHP ones and MySQL’s ones) are stored using 32 bits (i.e. 4 bytes) integers ; which means they are limited to a date range that goes from 1970 to 2038.

DATETIME don’t have that limitation — but are stored using more bytes (8 bytes, if I’m not mistaken)

After, between storing timestamps as seen by PHP, or timestamps as seen by MySQL :

using PHP timestamps means manipulations are easier from PHP — see Date/Time Functions

using MySQL’s timestamps means manipulations are easier from MySQL — see 11.6. Date and Time Functions

And, for more informations between MySQL’s TIMESTAMP and DATETIME datatypes, see 10.3.1. The DATETIME, DATE, and TIMESTAMP Types

source:

http://stackoverflow.com/questions/2533767/mysql-whats-the-best-to-use-unix-timestamp-or-datetime

http://stackoverflow.com/questions/409286/datetime-vs-timestamp