473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP MySQL object question

I am writing some new editing pages for a db using php. I want to use
an object approach for the underlying MySQL tables, and the edit page
will display related data from several tables. I am thinking about
creating a class for each table, and then a class for the "view." So, a
class (Client) for the db.client table would have members like
"CompanyNam e", "ID", etc. The class for the db.address table (address)
would have members like "City", "State", "zip", etc. Then the class for
the view would have members that are objects like Client, address, etc.
Can anyone give me any pros and cons of this approach, especially
since I will also need to create session variables to store and compare
data before and after editing.
Sep 14 '08 #1
16 1700
Hi,

Ruby on Rails implements ORM very well.

As for PHP,you might be interested in http://www.doctrine-project.org/.

Regards,
Box
boxoft...help people, serve people.
Sep 15 '08 #2
boxoft wrote:
Hi,

Ruby on Rails implements ORM very well.

As for PHP,you might be interested in http://www.doctrine-project.org/.

Regards,
Box
boxoft...help people, serve people.
Both interesting, but I'm at a point right now where learning a new
language, or application would be next to impossible.
Sep 15 '08 #3
William Gill wrote:
I am writing some new editing pages for a db using php. I want to use
an object approach for the underlying MySQL tables, and the edit page
will display related data from several tables. I am thinking about
creating a class for each table, and then a class for the "view." So, a
class (Client) for the db.client table would have members like
"CompanyNam e", "ID", etc. The class for the db.address table (address)
would have members like "City", "State", "zip", etc. Then the class for
the view would have members that are objects like Client, address, etc.
Can anyone give me any pros and cons of this approach, especially since
I will also need to create session variables to store and compare data
before and after editing.
That's one way to do it, and I use it quite a bit for low level
operations on the database. In more complicated applications I layer a
business object on top of the database objects.

Don't try to store large objects in your session, though. Better to
store id's in the session rather than the entire object.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 15 '08 #4
AqD
On Sep 16, 5:05*am, William Gill <nore...@exampl e.comwrote:
boxoft wrote:
Hi,
Ruby on Rails implements ORM very well.
As for PHP,you might be interested inhttp://www.doctrine-project.org/.
Regards,
Box
boxoft...help people, serve people.

Both interesting, but I'm at a point right now where learning a new
language, or application would be next to impossible.
It's easier to learn & use ORM rather than to write object<->db
interface by yourself ;)
Sep 16 '08 #5
AqD wrote:
On Sep 16, 5:05 am, William Gill <nore...@exampl e.comwrote:
>boxoft wrote:
>>Hi,
Ruby on Rails implements ORM very well.
As for PHP,you might be interested inhttp://www.doctrine-project.org/.
Regards,
Box
boxoft...he lp people, serve people.
Both interesting, but I'm at a point right now where learning a new
language, or application would be next to impossible.

It's easier to learn & use ORM rather than to write object<->db
interface by yourself ;)
Nonsense. Writing simple db objects such as this is quite easy.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 16 '08 #6
Jerry Stuckle wrote:
That's one way to do it, and I use it quite a bit for low level
operations on the database. In more complicated applications I layer a
business object on top of the database objects.
Not sure what you mean by "business object?"
>
Don't try to store large objects in your session, though. Better to
store id's in the session rather than the entire object.
Since I am only dealing with one composite record at a time (editing) I
was planning to store the original field data for before and after
comparison to determine when and where updates are needed. (12 - 20
fields, from 4 or 5 tables) I could do it as separate session
variables, but since each table record will have an associated object,
why not just store them that way? Or are you suggesting save the id in
a session variable, then re-select the db record and compare fields
(with incoming data) to see which need updating?

Sep 16 '08 #7
William Gill wrote:
Jerry Stuckle wrote:
>That's one way to do it, and I use it quite a bit for low level
operations on the database. In more complicated applications I layer
a business object on top of the database objects.
Not sure what you mean by "business object?"
Business objects are another OO layer on top of the database. They
server to further decouple the application code from the data storage.

For instance, a business object may get information from several
different tables, and when you update the data in the business object,
it updates the underlying tables.
>>
Don't try to store large objects in your session, though. Better to
store id's in the session rather than the entire object.
Since I am only dealing with one composite record at a time (editing) I
was planning to store the original field data for before and after
comparison to determine when and where updates are needed. (12 - 20
fields, from 4 or 5 tables) I could do it as separate session
variables, but since each table record will have an associated object,
why not just store them that way? Or are you suggesting save the id in
a session variable, then re-select the db record and compare fields
(with incoming data) to see which need updating?

Just store the id and later just update the data. MySQL is smart enough
not to update data which doesn't need to be changed. Or, if you don't
have all of the data in the object, reselect the row, update the object
then update the database. Unless your system is heavily used, chances
are the original row will still be in the database's cache and retrieval
will be very quick.

Of course, this is assuming no one else will be changing the data in the
meantime. If they are, you have to save the old data (the session would
work) and the second time around, fetch the data again. Compare the
saved data with that in the object; if there is a difference you need to
determine if it's important or not (i.e. if someone else updated column
'a' and you're updating column 'b', it's probably not a problem).

But just beware that when you save the object to the $_SESSION array,
PHP has to serialize it, then unserialize it later. This can be a bit
of overhead. And it can affect performance if your system is busy.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 16 '08 #8
AqD
On Sep 16, 6:16*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
AqDwrote:
On Sep 16, 5:05 am, William Gill <nore...@exampl e.comwrote:
boxoft wrote:
Hi,
Ruby on Rails implements ORM very well.
As for PHP,you might be interested inhttp://www.doctrine-project.org/..
Regards,
Box
boxoft...hel p people, serve people.
Both interesting, but I'm at a point right now where learning a new
language, or application would be next to impossible.
It's easier to learn & use ORM rather than to write object<->db
interface by yourself ;)

Nonsense. *Writing simple db objects such as this is quite easy.
Simple objects, yes.

How about this:

class Car
class SpecialCar extends Car
SELECT * FROM Car where color = 'red';

The list of result should include SpecialCar(s) and have them in
correct type (and all derived classes from 'Car').

And the driver (another class) and other properties in 'Car' should be
fetched, too. Being fetched with the result list (by join) or later
when they're actually accessed. The laziness of related objects must
also be customized, in model classes and/or in query.

And a .save method to save this object and all related ones (also
check for modification), and make inserts if needed.
That is what ORMs like Hibernate are supposed to do for you.
Sep 16 '08 #9
Jerry Stuckle wrote:
William Gill wrote:
>Jerry Stuckle wrote:
>>That's one way to do it, and I use it quite a bit for low level
operations on the database. In more complicated applications I layer
a business object on top of the database objects.
Not sure what you mean by "business object?"

Business objects are another OO layer on top of the database. They
server to further decouple the application code from the data storage.

For instance, a business object may get information from several
different tables, and when you update the data in the business object,
it updates the underlying tables.
I thought so. This is in essence what I am doing.

Just store the id and later just update the data. MySQL is smart
enough
not to update data which doesn't need to be changed...
I was unaware MySQL could/would make such a determination. Now that I
think of it, the not changing the timestamp is the only reason it would
matter for what I'm doing.
>...Or, if you don't
have all of the data in the object, reselect the row, update the object
then update the database. Unless your system is heavily used, chances
are the original row will still be in the database's cache and retrieval
will be very quick.

Of course, this is assuming no one else will be changing the data in the
meantime. If they are, you have to save the old data (the session would
work) and the second time around, fetch the data again. Compare the
saved data with that in the object; if there is a difference you need to
determine if it's important or not (i.e. if someone else updated column
'a' and you're updating column 'b', it's probably not a problem).

But just beware that when you save the object to the $_SESSION array,
PHP has to serialize it, then unserialize it later. This can be a bit
of overhead. And it can affect performance if your system is busy.
I know, but, at least in the current case, the performance hit and/or
simultaneous user updating aren't an issue.
Sep 16 '08 #10

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

Similar topics

2
1623
by: j-marvin | last post by:
hi- i have a book on mysql written for version 4 that has hard to read screen shots. i'd like to get a newer mysql book. do i have to worry about the version number of mysql i am using if i use php 4.3 version or newer? i'd like to get the osbourne mysql book. the only thought that comes to mind is some things may be deprecated since the...
0
2299
by: MJL | last post by:
This is a mysql/php question (but a little more on the mysql side.) The two are so closely related these days, I thought it would be ok to ask here. I installed on my Suse Linux system mysql 4.0 using an rpm. I also installed all of the appropriate PHP 4.3 and Apache 2.0 rpms. I set my socket path in my.cnf to /tmp/mysql.sock. I then,...
2
3998
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum default is 4 letters). This is the Fed. Everything is a TLA (three-letter acronym). Therefore, since I'm building a PORTABLE web application,...
0
5757
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default setting whereby the minimum amount of characters is 4 for a search. Being that we're government and full of TLA (three-letter acronyms), that is not...
175
11247
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I think is PostgreSQL would have less USP's (Uniqe Selling Points
1
3430
by: grabro | last post by:
Having just upgraded to from Suse 10.0 to 10.1 mysql-administrator will not work. When I try to acccess it I get the following message. linux:/home/grabro # mysql-administrator /usr/bin/mysql-administrator-bin: Symbol `_ZTIN4Glib9InterfaceE' has different size in shared object, consider re-linking /usr/bin/mysql-administrator-bin: Symbol...
1
1297
by: Tom | last post by:
I use the adodb_lite class and I'm getting curious results with a wrapper function I've written to insert an array in a table. The function has an optional parameter to verify columns (the array keys) before executing the statement. It runs this statement: "SHOW COLUMNS FROM `$table`" (I've added a larger code snippet below.) What is...
27
3875
by: gerrymcc | last post by:
Hello, I'm a php/mysql beginner... Is there any way of making the mysql command line client full-screen? Sometimes it's easier to use the client than go thru php, but since it's only about 80 characters wide that limits its usefulness. Thanks, Gerard http://homepage.eircom.net/~gerfmcc]
4
2414
by: Michael Sharman | last post by:
Hi guys, I'm a little confused with dates. Ok, all I want to do is store a date in MySQL as a datetime object and be able to read and format it using PHP. My datatype in MySQL is DATETIME and I'm inserting a date using the MySQL function now(). So far so good. When I var_dump() the value from the database it says it's a string,
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.