Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage
Php > Database Related sample source codes
Better PostgreSQL Metadata Function
Better PostgreSQL Metadata Function 0 and a.attrelid = c.oid and c.relname = '."'$table'".' and a.atttypid = t.oid order by a.attnum'; $qid = pg_Exec($db, $sql); // Check error if (!is_resource($qid)) { print('MetaData(): Query Error - table does not exist'); return null; } $rows = pg_NumRows($qid); // Store meta data for ($i = 0; $i < $rows; $i++) { $field_name = pg_Result($qid,$i,1); // Field Name $meta[$field_name]['id'] = pg_Result($qid,$i,0); // Attrbute ID $meta[$field_name]['type'] = pg_Result($qid,$i,2); // Data type name $meta[$field_name]['len'] = pg_Result($qid,$i,3); // Length: -1 for variable length $meta[$field_name]['modifier'] = pg_Result($qid,$i,4); // Modifier $meta[$field_name]['notnull'] = (pg_Result($qid,$i,5) === 't' ? TRUE : FALSE); // Not NULL? $meta[$field_name]['hasdefault'] = (pg_Result($qid,$i,6) === 't' ? TRUE : FALSE); // Has default value? } // Clean up. PHP4 reference count code would be smart enough to do this, though. pg_FreeResult($qid); return $meta; } //// Test code //// $dbName = 'db_session'; // Change this to your db name $dbUser = 'yohgaki'; // Change this to your db user name $tableName = 'sys_session'; // Change this to your table name $db = pg_connect('host=dev dbname='.$dbName.' user='.$dbUser); $meta = metadata($db, $tableName); print("
\n"); print_r($meta); print("</pre>\n"); ?>
Privacy Policy
|
Link to Us
|
Links