ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_dictionary:start_lesson

Introduction

ADOdb provides numerous methods that allow the interrogation of the structure of the database from the database level all the way down to the field object. It does so in a way that offers the following assistance:

  • Provides a simple, consistent interface to the information
  • Simplifies the procedure of adding,changing and deleting the structure of the database
  • Provides cross-database compatibility
  • Hides sometimes complex commands that allow access to database schema information.

The Meta Functions

In ADOdb, methods and objects that hide the complexity of the internals of the database are often referred to as Meta Functions and Meta Objects. These methods can be used to access and update the schema in the database.

Hiding Complexity

In the following example, we want to query the schema of a table in Microsoft SQL server to obtain a list of the columns. Firstly we do it using the native mode syntax for SQL Server:

$SQL =	"select c.name,
	t.name as type,
	c.length,
	c.xprec as precision,
	c.xscale as scale,
	c.isnullable as nullable,
	c.cdefault as default_value,
	c.xtype,
	t.length as type_length,
	sc.is_identity
	from syscolumns c
	join systypes t on t.xusertype=c.xusertype
	join sysobjects o on o.id=c.id
	join sys.tables st on st.name=o.name
	join sys.columns sc on sc.object_id = st.object_id and sc.name=c.name
	where o.name='myTable'";
print_r($db->getAll($SQL));

Next we do the same thing using the ADOdb MetaFunction, metaColumns().

$print_r($db->metaColumns('myTable');

The 2 previous examples return the same data, but in the case of ADOdb, the command can be issued against any supported database and the result will be the same

v5/userguide/learn_dictionary/start_lesson.txt · Last modified: 2016/03/16 01:35 by mnewnham