Skip to content

Instantly share code, notes, and snippets.

@davidrenne
Created March 9, 2013 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidrenne/5124199 to your computer and use it in GitHub Desktop.
Save davidrenne/5124199 to your computer and use it in GitHub Desktop.
db connection php script
CREATE TABLE IF NOT EXISTS `database_connections` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`connection_id` int(11) NOT NULL,
`queries` text NOT NULL,
`page` varchar(300) NOT NULL,
`ip_address` varchar(255) NOT NULL,
`t_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `connection_unique` (`connection_id`),
KEY `connection_id` (`connection_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
mysql_query(
"
INSERT INTO
database_connections
SET
connection_id = CONNECTION_ID(),
queries = '".mysql_real_escape_string($query_string)."',
page = '".mysql_real_escape_string($_SERVER['REQUEST_URI'])."',
ip_address = '".(!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : mysql_real_escape_string(print_r($_SERVER,true)))."'
ON DUPLICATE KEY UPDATE queries=CONCAT(queries,'\n\n\n','".mysql_real_escape_string($query_string)."');
"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment