PHP Velho Oeste 2024

mssql_field_length

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

mssql_field_lengthフィールド長を得る

警告

この関数は PHP 7.0.0 で 削除 されました。

この関数の代替として、これらが使えます。

説明

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

結果 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 2 notes

up
0
zz(lost dot childz at gmail dot com)
16 years ago
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;
up
0
Anonymous
19 years ago
You can also work around this limitation with the following:

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