It is important to point out that the result of both
SELECT ' '
and
SELECT ''
is the string ' '.
That is, the php mssql functions will return a phantom space for any empty strings.
See http://bugs.php.net/bug.php?id=26996 and http://bugs.php.net/bug.php?id=25777
PHP does not classify this as a "bug" because the MS DBLib cannot tell the difference betwene the two cases. Earlier versions of php trim'd strings automatically.
It may be a good idea to ltrim and rtrim your results in some cases.
mssql_fetch_object
(PHP 4, PHP 5, PECL odbtp >= 1.1.1)
mssql_fetch_object — オブジェクトとして行を取得する
説明
object mssql_fetch_object
( resource
$result
)mssql_fetch_object() は mssql_fetch_array() に似ていますが、配列の代わりに オブジェクトが返されるという違いがあります。 間接的にこのことは、データをフィールド名でのみアクセスすることが 可能であり、そのオフセットではアクセスできないことを意味します (番号はプロパティ名としては使用できません)。
速度面でこの関数は mssql_fetch_array() と同等であり、 mssql_fetch_row() とほとんど同じです (違いは僅かです)。
返り値
取得された行に対応するプロパティを有するオブジェクト、
またはもう行がない場合に FALSE を返します。
例
例1 mssql_fetch_object() の例
<?php
// select クエリを MSSQL に送信します
$query = mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]');
// レコードが存在するかどうかを調べます
if (!mssql_num_rows($query)) {
echo 'No records found';
} else {
// ユーザー一覧を
// * name (username) 形式で表示します
echo '<ul>';
while ($row = mssql_fetch_object($query)) {
echo '<li>' . $row->name . ' (' . $row->username . ')</li>';
}
echo '</ul>';
}
// 結果を開放します
mssql_free_result($query);
?>
注意
注意: この関数により返されるフィー ルド名は 大文字小文字を区別 します。
注意: この関数は、 NULL フィールドに PHPの
NULL値を設定します。
rubin at afternet dot org ¶
8 years ago
klystofer at brturbo dot com ¶
9 years ago
<?php
/*
A simple example using mssql_fetch_object
*/
$conexao = mssql_connect("myServer","myUser","myPass");
mssql_select_db("myDB",$conexao);
$query = mssql_query("SELECT EMPRESA FROM IDENTIFICACAO ORDER BY EMPRESA;");
while ($retorno = mssql_fetch_object($query))
echo "Empresa:" . $retorno->EMPRESA;
?>
