PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_Table » Bug #6749

Wondering if you'd like to use this as a log example

Details

Request #6749Wondering if you'd like to use this as a log example
Submitted2006-02-11 01:13 UTC
Frombenjaminhill at gmail dot com
StatusBogus
PackageDB_Table
PHP Version5.0.5
OSWinXP
Roadmaps(Not assigned)

Comments

[2006-02-11 01:13 UTC] benjaminhill at gmail dot com

Description:
------------
Made the following for my own project - if you think it would make a good example of the no-SQL clean code you can get out of DB_TABLE, great! (Or if you have any suggestions, always looking to improve)

Test script:
---------------
<?php

require_once 'DB.php';
require_once 'DB/Table.php';

function iif($expression, $returntrue, $returnfalse = '') {
return ($expression ? $returntrue : $returnfalse);
}

class Log extends DB_Table {
public $col = array(
'id' => array(
'type' => 'integer',
'require' => true
),
'ip' => array(
'type' => 'varchar',
'size' => 16
),
'page' => array(
'type' => 'varchar',
'size' => 255
),
'referrer' => array(
'type' => 'varchar',
'size' => 255,
),
'signdate' => array(
'type' => 'timestamp',
'require' => true
),
'useragent' => array(
'type' => 'varchar',
'size' => 255
),
'remotehost' => array(
'type' => 'varchar',
'size' => 255
)
);

public $idx = array(
'id' => 'unique',
'signdate' => 'normal'
);

static function logHit() {
global $db;
$log =& new Log($db, 'log', 'safe');
$referer = null;

if(isset($_SERVER['HTTP_REFERER'])) {
$referer = $_SERVER['HTTP_REFERER'];
}

$cols_vals = array(
'ip' => $_SERVER['REMOTE_ADDR'],
'page' => "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}".iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", ""),
'referrer' => $referer,
'signdate' => mktime(),
'useragent' => $_SERVER['HTTP_USER_AGENT'],
'remotehost'=> @getHostByAddr($_SERVER['REMOTE_ADDR'])
);
$result = $log->insert($cols_vals);
}

// Override
function insert($data) {
$data['id'] = $this->nextID();
$result = parent::insert($data);
if (PEAR::isError($result)) {
return $result;
} else {
return $data['id'];
}
}
}
?>

[2006-02-13 21:34 UTC] benjaminhill at gmail dot com

wrong forum for this.