Return to Snippet

Revision: 13748
at May 5, 2009 10:26 by Eloi


Initial Code
Create Table Sessions (
  session_id INT UNSIGNED NOT NULL AUTOINCREMENT,
  ip_address INT UNSIGNED NOT NULL,
  session_data TEXT NOT NULL,
  PRIMARY KEY (session_id),
  INDEX (ip_address)
) ENGINE=InnoDB

// Insert a new dummy record
INSERT INTO Sessions VALUES (NULL, INET_ATON('192.168.0.2'), 'some session data');

//Find all sessions coming from a local subnet
SELECT
  sessin_id,
  ip_address as ip_raw,
  INET_NTOA(ip_address) as ip,
  session_data
FROM Sessions
WHERE ip_address
BETWEEN INET_ATON('192.168.0.1')
AND INET_ATON('192.168.0.255')

Initial URL

                                

Initial Description
Saving the IP as Int we save a lot of space and permit do beautibul selects

Initial Title
Create Table Sessions

Initial Tags
mysql, ip

Initial Language
MySQL