downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mssql_field_name> <mssql_fetch_row
Last updated: Fri, 13 Nov 2009

view this page in

mssql_field_length

(PHP 4, PHP 5, PECL odbtp >= 1.1.1)

mssql_field_lengthフィールド長を得る

説明

int mssql_field_length ( resource $result [, int $offset = -1 ] )

結果 result のフィールド番号 offset のフィールド長を返します。

パラメータ

result

処理対象となる結果リソース。これは mssql_query() のコールによって取得します。

offset

フィールドオフセット。0 から始まります。 省略した場合は現在のフィールドを使用します。

返り値

成功した場合は指定したフィールドの長さ、 失敗した場合は FALSE を返します。

例1 mssql_field_length() の例

<?php
// MSSQL に接続します
mssql_connect('MANGO\SQLEXPRESS''sa''phpfi');
mssql_select_db('php');

// select クエリを MSSQL に送信します
$query mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]');

// フィールドの型と長さを表示します
echo 'The field \'age\' has a data length of ' mssql_field_length($query1);

// 結果を開放します
mssql_free_result($query);
?>

上の例の出力は、 たとえば以下のようになります。

The field 'age' has a data length of 4

注意

注意: Windows ユーザへの注意
PHP が使用している API(MS DbLib C API)の制限により、 VARCHAR フィールドの長さは 255 までに限定されます。それ以上のデータを保存したい場合は、かわりに TEXT フィールドを使用します。

参考



add a note add a note User Contributed Notes
mssql_field_length
zz(lost dot childz at gmail dot com)
31-Oct-2007 11:41
there are same problem with VARBINARY, if you are forced to use existing database with such fields you can do it like this:

SELECT CAST(master.dbo.fn_varbintohexstr(VARBINARYFIELD) AS TEXT) FROM table;
08-Feb-2005 09:56
You can also work around this limitation with the following:

   -- for example, with MyVarCharField VARCHAR(1000)
   SELECT CAST(MyVarCharField AS TEXT) FROM MyTable

mssql_field_name> <mssql_fetch_row
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites