PHP Velho Oeste 2024

mssql_fetch_object

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

mssql_fetch_objectオブジェクトとして行を取得する

警告

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

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

説明

mssql_fetch_object ( resource $result ) : object

mssql_fetch_object()mssql_fetch_array() に似ていますが、配列の代わりに オブジェクトが返されるという違いがあります。 間接的にこのことは、データをフィールド名でのみアクセスすることが 可能であり、そのオフセットではアクセスできないことを意味します (番号はプロパティ名としては使用できません)。

速度面でこの関数は mssql_fetch_array() と同等であり、 mssql_fetch_row() とほとんど同じです (違いは僅かです)。

パラメータ

result

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

返り値

取得された行に対応するプロパティを有するオブジェクト、 またはもう行がない場合に 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 値を設定します。

参考

add a note add a note

User Contributed Notes 2 notes

up
0
rubin at afternet dot org
19 years ago
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.
up
-3
klystofer at brturbo dot com
20 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;

?>
To Top