473,224 Members | 1,292 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

class / mysql_fetch_object

Hello :)
class MyClass {
var $ID;
var $NAME;
var $SIZE;
}

$blabla = new MyClass();

Then i have in a mysqldb a table with following fields
ID, NAME, SIZE

So :) Now i get a row from the table and fetch it using
mysql_fetch_object.

$result = mysql_query("SELECT * FROM sometable LIMIT 0,1");
$row = mysql_fetch_object($result);

As You can see :) $row has the same properties as $blabla.

My question: is there a way to 'convert' the object
$row to te class MyClass without doin' it like this

$blabla->ID = $row->ID;
$blabla->NAME = $row->NAME;
$blabla->SIZE = $row->SIZE;
I would like simply to assign the values of the properties of $row
to $blabla.
thanks for any help :)
websafe

--
http://www.partybitchez.org/
Jul 17 '05 #1
1 2328
websafe <pl****@dont.write.me> wrote:
Ok :) i've found a solution:

<?php
class MyClass {
var $ID;
var $NAME;
var $SIZE;

function MyClass($obj) {
$arr = array_keys(get_object_vars($obj));
for($i = 0 ; $i < count ($arr); $i++ ) {
eval('$this->' . "{$arr[$i]} = '{$obj->$arr[$i]}';");
}
}
}

$result = mysql_query("SELECT * FROM sometable LIMIT 0,1");
$row = mysql_fetch_object($result);
$assigned = new MyClass($row);
?>

--
http://www.partybitchez.org/
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sundial Services | last post by:
I recently brought an old application out of mothballs and launched it under PHP5, only to get this message: Fatal Error: Class '1' not found It was clearly somehow an /execution/ time...
2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
2
by: Alucard | last post by:
Hi all. I am a newbie in PHP. Recently I found that there are mainly two ways to fetch mysql(or other DB) data: by object or by array. What is the main differences between them? Will the...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
3
by: Paul Lautman | last post by:
Are there any benefits to using mysql_fetch_object() instead of mysql_fetch_assoc()?
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
3
by: Bob Bedford | last post by:
Hi all, wondering if does exists a mysql to html table function or class written in PHP. something like. createtable($query,fieldname1,fieldname2,fieldname3,); the last parameter would...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.