mysql_fetch_object
]Podporované v PHP 4, PHP 5
Syntax
object mysql_fetch_object ( resource $result [, string $class_name [, array $params ] ] )
Popis
Príkaz jazyka PHP
Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead.
Parametre
result - The result resource that is being evaluated. This result comes from a call to mysql_query().
class_name - The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned.
params - An optional array of parameters to pass to the constructor for class_name objects.
Vrátená hodnota
Returns an object with string properties that correspond to the fetched row, or FALSE if there are no more rows.
Príklad 1
<?php
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select * from mytable");
while ($row = mysql_fetch_object($result)) {
echo $row->user_id;
echo $row->fullname;
}
mysql_free_result($result);
?>
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select * from mytable");
while ($row = mysql_fetch_object($result)) {
echo $row->user_id;
echo $row->fullname;
}
mysql_free_result($result);
?>
Príklad 2
<?php
class foo {
public $name;
}
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select name from mytable limit 1");
$obj = mysql_fetch_object($result, 'foo');
var_dump($obj);
?>
class foo {
public $name;
}
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select name from mytable limit 1");
$obj = mysql_fetch_object($result, 'foo');
var_dump($obj);
?>
Pozri aj
mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_row, mysql_data_seek, mysql_query
]