mysql_fetch_object
Get a row from the result set as an object.
Function name: mysql_fetch_object()
Applicable versions: PHP 4, PHP 5 (deprecated for PHP 7.0.0 and removed in PHP 7.2.0)
Usage: mysql_fetch_object(resource $result [, string $class_name = "stdClass" [, array $params]])
Description: The mysql_fetch_object() function is used to obtain the next row from the result set as an object.
parameter:
Return value:
Example:
$result = mysql_query("SELECT * FROM users"); while ($row = mysql_fetch_object($result)) { echo $row->name . " - " . $row->email . "<br>"; }
class User { public $name; public $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } } $result = mysql_query("SELECT name, email FROM users"); while ($row = mysql_fetch_object($result, "User", ["John Doe", "john@example.com"])) { echo $row->name . " - " . $row->email . "<br>"; }
Notes:
mysql_fetch_object()
function has been deprecated and is no longer recommended. It is recommended to use mysqli_fetch_object()
or PDO::fetchObject()
instead.mysql_fetch_object()
has been removed and cannot be used.