mysql_fetch_object()

It returns a row from a recordset as an object

Example

<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_object($userQry)){
print_r($userInfo);
}

Output

stdClass Object
(
[id] => 1
[name] => PHP
)
stdClass Object
(
[id] => 2
[name] => JS
)
stdClass Object
(
[id] => 3
[name] => HTML
)
stdClass Object
(
[id] => 4
[name] => AS
)

 

Share