May 1, 2011
How to get records from MySQL into value objects with PHP
Question by user733284
I have this code:
$Result = DBQuery("SELECT user_id,nick_name,email FROM users LIMIT $fromindex.",".$numOfUsers);
if ($Result)
{
$resultUsers->UersData=$Result;
}
The problem is that the results U get are in some kind of format that i don’t know.
I want to get the results in array format, which every element of that array should be a value object class of this type:
class UserVO {
var $_explicitType="UserVO";
var $id;
var $nickName;
var $email;
}
Any idea how it can be done?
Answer by Starx
My answer might not sound very helpful, regarding your unclear question. I am supposing, that the function DBquery
returns the result of mysql_query(......)
. If thats true, then you are feeding the userData
with a Resource string
which is a resource data type.
There are few ways to access such resource String
-
If the query exports multiple results
while($row = mysql_fetch_assoc($userData) { print_r($row); //This is where you will get your mysql rows. }
-
If the query return single row
$row = mysql_fetch_assoc($userData); print_r($row); // //This is where you will get your mysql rows.
Here are some must check links