registry

The functions registry_get, registry_set and registry_delete implement a permanent registry for saving variables with their values.

Variables are registered in the table registry of the DB.

CREATE TABLE `izend_registry` (
  `name` VARCHAR(100) NOT NULL,
  `value` longtext NOT NULL,
  PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

The values of the variables are serialized.

registry_get
SYNOPSIS

registry_get($name, $default=false)

DESCRIPTION

registry_get returns the value of the variable previously registered with the name $name. If $name isn't a registered variable, or in case of error, registry_get returns the value specified by $default.

CODE
  1. function registry_get($name, $default=false) {
  2.     $sqlname=db_sql_arg($name, false);
  3.  
  4.     $tabregistry=db_prefix_table('registry');
  5.  
  6.     $sql="SELECT value FROM $tabregistry WHERE name=$sqlname";
  7.  
  8.     $r = db_query($sql);

registry_get executes an SQL request which extracts the value of the variable $name from the table registry, then unserializes the returned value before returning it. Note how the functions db_sql_arg and db_prefix_table are used. If the variable $name doesn't exist, registry_get returns the value given by $default which is false by default.

registry_set
SYNOPSIS

registry_set($name, $value)

DESCRIPTION

registry_set registers the variable $name with the value $value. If $name is already registered, its value is replaced.

registry_set returns true, or false in case of error.

CODE
  1. }
  2.  
  3. function registry_set($name, $value) {
  4.     $sqlname=db_sql_arg($name, false);
  5.     $sqlvalue=db_sql_arg(serialize($value), true);
  6.  
  7.     $tabregistry=db_prefix_table('registry');

registry_set executes an SQL request which adds the variable $name with the serialized value of $value in the table registry. If $name is already registered in the table, the SQL request does an update of its value.

registry_delete
SYNOPSIS

registry_delete($name)

DESCRIPTION

registry_delete deletes the variable previously registered with the name $name.

registry_delete returns true, or false in case of error.

CODE
  1.  
  2.     $r = db_insert($sql);
  3.  
  4.     if ($r) {
  5.         return true;
  6.     }

registry_delete executes an SQL request which deletes the variable $name from the table registry.

SEE ALSO

db, cron

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

===

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].