How to implement function like fetch_object and the purpose of using it?
I have to use Array to fetch_array to fetch a row from a result set... in what way the fetch_object function is useful... at which situation it is used? my another question to you is, why do we want to put them into "another" variable? the $row["field_name"]; if it is already a variable.
Re: How to implement function like fetch_object and the purpose of using it?
Fetch array normally retrieves the records based on array index. i.e. like $row[1] but if you want to retrieve the record based on the column name we can use fetch_object i.e. $row['username']
object maxdb_fetch_object ( object $result )
Object oriented style (method):
result
object fetch_object ( void )
One feature to assist you is the MySQLi class, which allows for an object-oriented approach to database manipulation. The maxdb_fetch_object() will return the current row result set as an object where the attributes of the object represent the names of the fields found within the result set. If no more rows exist in the current result set, NULL is returned.
Re: How to implement function like fetch_object and the purpose of using it?
mysqli_result::fetch_object -- mysqli_fetch_object — Returns the current row of a result set as an object. MySQLi stands for MySQL Improved, and is available from MySQL versions >= 4.1.3 and must be compiled in PHP with –with-mysqli=/path/to/mysql/bin/mysql_config.
fetch_object will be implemented under the Object oriented style (method):
Code:
object mysqli_result::fetch_object ([ string $class_name [, array $params ]] )
Re: How to implement function like fetch_object and the purpose of using it?
So it's just a facility and not a burden on anybody. If you're following OOPs pattern then you may use mysql_fetch_object function otherwise get the processing done using mysql_fetch_assoc function. The mysqli_fetch_object() will return the current row result set as an object where the attributes of the object represent the names of the fields found within the result set.