ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:setcustomactualtype

This is an old revision of the document!


setCustomActualType

See Also

From Version 5.22
setCustomMetaType

Syntax
bool setCustomActualType(
       string $actualType,
       string $metatType
       )

Description

The function setCustomActualType() takes an input string that represents a physical database data type, and creates an ADOdb [v5:dictionary:metattype|metaType]] associated with it. If the physical type is already bound to an existing metaType, the new setting overrides the old setting. For full functionality, a corresponding setCustomMetaType() command should be issued.

Examples

Creating A New Type

The system can be expanded to accept geometry type data types by creating new types

/*
* $db = MySQL connection assumed
*/
 
/*
* First link the MySQL geometry type to a new metaType
*/ 
$ok = $db->setCustomActualType(255,'P');
 
/*
* Now tell ADOdb how to handle the data in inserts and updates
* see the entry for setCustomMetaType for an explanation
*/
$ok = $db->setCustomMetaType('P','POINT');
 
/*
* Insert a record with a point column
*/
$ar = array();
$ar['geo_column'] = 'POINT(1,2)';
 
/*
* Use getinsertsql to generate the insert statement
*/
$sql = "SELECT * FROM geo_table WHERE rowid=0";
$result = $db->execute($sql);
 
$sql = $db->getInsertSql($result,$ar);
 
/*
* returns "INSERT INTO geo_table ( GEO_COLUMN ) VALUES ( POINT(1,2) )"
*/

Overriding An Existing Type

The system can be used to control the behavior of existing types. For example, in ADOdb V5.22, the D metatype in the Micosoft SQL Server points to Physical DATE type field, instead of the DATETIME field previously used. To make code compatible with previous versions, the following method can be used.

/*
* $db = SQL Server connection assumed
*/
 
/*
* Point the actual type to a D metatype.
*/
$db->setCustomActualType(SQLSRV_SQLTYPE_DATETIME2 , 'D');
 
/*
* Point the metatype D back to the datetime2 type, and tell it 
* to handle the data as datetime
*/
$db->setCustomActualType('D', SQLSRV_SQLTYPE_DATETIME2, 'T');
v5/reference/connection/setcustomactualtype.1609815130.txt.gz · Last modified: 2021/01/05 03:52 by mnewnham