Using mySQL for storage

Submitted by xqus on Tue, 12/20/2011 - 23:19

Important: mySQL for storage is only available in phpSec 0.2-beta.

To be able to use mySQL to store all your phpSec data you need PHP with the PDO extension installed. All the latest versions of PHP has this enabled by default, so this should not be a big problem. phpSec only use one table, so we don't need a seperate database, unless you want one.

Setting up the table

The following table is needed by phpSec. You can call it whatever you want, but phpsec is probably fine.

--
-- Table structure for table `phpsec`
--

CREATE TABLE IF NOT EXISTS `phpsec` (
  `type` varchar(255) NOT NULL COMMENT 'Type of data.',
  `id` varchar(255) NOT NULL COMMENT 'Item ID.',
  `mac` binary(32) NOT NULL COMMENT 'Message Authentication Message.',
  `time` int(11) unsigned NOT NULL COMMENT 'Unix time stamp of creation time.',
  `data` text NOT NULL COMMENT 'Serialized object.',
  UNIQUE KEY `id` (`id`),
  KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

After you have created your table you should be all set to configure phpSec to use mySQL.

Setting up phpSec

In order to use mySQL you will need to pass the database connection settings trough the phpsec::$_dsn variable.

phpsec::$_dsn = 'mysql:' .
    'dbname=xstore;' .
    'table=phpsec;' .
    'host=localhost;' .
    'username=xstore;' .
    'password=123abc';

The above is an example of how your string may look like. The string consists of several configuration opions and their values. The following options are available and all of them are required. The order is not important.

Variable Description
dbname Name of your database.
table Name of the table. Should be phpsec if you didn't change it when creating the table.
host Hostname to your mySQL server. Usually localhost.
username Your database username.
password Your database password.

After telling phpSec what database and table to store data in, you should continue reading the Getting started chapter in the phpSec manual.

Copyright (c) 2011, 2012 Audun Larsen.

Drupal theme by Kiwi Themes.