It is 3 files, all pretty short:
function.php :
Code: Select all
function db_on() {
$link=mysql_connect(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD) or die('The mySQL server is down');
mysql_select_db(DB_DATABASE,$link) or die('mySQL database problem');
define('_sql',$link);
}
function quote($value) {
if (get_magic_quotes_gpc()) $value=stripslashes($value);
$value='\''.mysql_real_escape_string($value).'\'';
return $value;
}
function db_off() {
mysql_close(_sql);
}
constant.php :
Code: Select all
<?php
define('HTTP_SERVER', 'http://localhost');
define('HTTPS_SERVER', 'http://localhost');
define('ENABLE_SSL', false);
define('HTTP_COOKIE_DOMAIN', 'localhost');
define('HTTPS_COOKIE_DOMAIN', 'localhost');
define('HTTP_COOKIE_PATH', '/');
define('HTTPS_COOKIE_PATH', '/');
define('DIR_WS_INCLUDES', 'inc/');
define('DB_SERVER', 'localhost');
define('DB_SERVER_USERNAME', 'mydb_username');
define('DB_SERVER_PASSWORD', 'pw1234');
define('DB_DATABASE', 'mydb');
define('USE_PCONNECT', 'false');
define('STORE_SESSIONS', 'mysql');
?>
test.php :
Code: Select all
<?php
session_start();
require_once('inc/constant.php');
require_once('inc/function.php'); //basic functions
db_on();
$sql='SELECT date FROM mydb WHERE date < CURRENT_DATE()';
IF($sql){
$sql='UPDATE mydb SET yesterday = today';
}
$res=mysql_query($sql,_sql);
db_off();
?>
let's say today's date is 11/18/2009
That db part looks like this:
yesterday today date
1000 1500 2009-11-17
100 200 2009-11-17
555 657 2009-11-17
Because date is less than CURRENT_DATE() it should end up like this:
yesterday today date
1500 1500 2009-11-18
200 200 2009-11-18
657 657 2009-11-18
However if the date is already today's date like this:
yesterday today date
1500 2000 2009-11-18
200 300 2009-11-18
657 700 2009-11-18
Than today must not overwrite yesterday!
Then I will replace the today column's data, but that is a whole different story, and that part of the code is already working...