PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #5241

MSSQL table info is inadequate

Details

Request #5241MSSQL table info is inadequate
Submitted2005-08-30 13:02 UTC
Fromchx at mail dot tvnet dot hu
StatusWont fix
PackageDB
PHP Version4.3.10
OSWindows
Roadmaps(Not assigned)

Comments

[2005-08-30 13:02 UTC] chx at mail dot tvnet dot hu

Description:
------------
Using information from user comments (some already deleted) in the PHP manual, I have found that if you want a DB dumper script then you need information whether a field is nvarchar or ntext (opposed to varchar/text). (You want to mssql_query ("set TEXTSIZE 100000;"); and select cast ( column_name as text ) as column_name ... otherwise php mssql extension barks.)

I below inserted a limited reimplementation of tableInfo which only supports $tablename as string.

Test script:
---------------
result = mssql_query(
"SELECT sysobjects.name AS tableName, syscolumns.name AS columnName, systypes.name AS
columnType, syscolumns.length AS columnLength
FROM sysobjects INNER JOIN
syscolumns ON sysobjects.id = syscolumns.id INNER JOIN
systypes ON syscolumns.type = systypes.type AND syscolumns.xusertype =
systypes.xusertype WHERE sysobjects.name = '$tablename'");
while ($column = mssql_fetch_assoc($result)) {
$res[] = array(
'table' => $column['tableName'],
'name' => $column['columnName'],
'type' => $column['columnType'],
'len' => $column['columnLength'],
// We only support flags for table
'flags' => ''
);
}

return $res;
}

[2005-08-30 15:30 UTC] chx at mail dot tvnet dot hu

The function I recommended was not good enough. This query http://searchvb.techtarget.com/tip/1,289483,sid8_gci876303,00.html?bucket=ETA works better.

<?php
function tableInfo($tablename, $mode = null)
{
$result = mssql_query( "SELECT sysobjects.name AS [table],syscolumns.name AS name, systypes.name AS type, syscolumns.length AS len FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id INNER JOIN systypes ON syscolumns.xtype = systypes.xtype WHERE sysobjects.name = '$tablename' AND sysobjects.xtype='U' ");
while ($column = mssql_fetch_assoc($result)) {
$res[] = $column;
}
return $res;
}

?>