Function Module
Описание
The Function module provides methods for executing non-standard SQL database functions in a consistent way. The following document lists the available methods, providing examples of their use. To include the Function module functionality, you need to load it first.
Loading the Function module
<?php
require_once 'MDB2.php';
$dsn = 'pgsql://someuser:apasswd@somehost';
$mdb2 =& MDB2::factory($dsn);
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
// loading the Function module
$mdb2->loadModule('Function');
?>
After including the module, you can access its methods like this:
Get the length of a string expression
<?php
// PHP5
$mdb2->length('expression');
// PHP4 and PHP5
$mdb2->function->length('expression');
?>
Further in the document the PHP5-compatible way will be used.
Concatenate strings
<?php
$mdb2->concat('string1', 'string2');
?>
Execute a Stored Procedure
Supposing we have the following Stored Procedure (MySQL syntax):
DELIMITER // CREATE PROCEDURE procedure1 (IN parameter1 INTEGER) BEGIN DECLARE variable1 CHAR(10); IF parameter1 = 17 THEN SET variable1 = 'birds'; ELSE SET variable1 = 'beasts'; END IF; INSERT INTO table1 VALUES (variable1); END // DELIMITER ;
we can call it this way:
Execute a Stored Procedure
<?php
$params = array(17);
$mdb2->executeStoredProc('procedure1', $params);
?>