Database Interface class, method design help
Moderator: General Moderators
Database Interface class, method design help
Hey,
I'm writing a class that will i'm going to use in my php applications to interface with whatever database we are using. The goal of this class is to allow me to change how / where I store my data without having to change any application code.
I've just started to write the method that will be used for deleting entries from the database but i'm having trouble figuring out how to do it. I'd like to be able to use this method to set multiple conditions using a number of different comparison operators.
For example, say I want to delete every entry in the database where a field 'age' is less than 15 or the field 'age' > 30. How could I do this?
Thanks a bunch for any help / advice provided.
I'm writing a class that will i'm going to use in my php applications to interface with whatever database we are using. The goal of this class is to allow me to change how / where I store my data without having to change any application code.
I've just started to write the method that will be used for deleting entries from the database but i'm having trouble figuring out how to do it. I'd like to be able to use this method to set multiple conditions using a number of different comparison operators.
For example, say I want to delete every entry in the database where a field 'age' is less than 15 or the field 'age' > 30. How could I do this?
Thanks a bunch for any help / advice provided.
Why do you need a method for deleting? You delete entries in the db using an SQL query. All you need is a method for passing queries. You can create other classes which define the behaviours and methods of objects which control specific queries as needed, but they probably should not be in the DBAL class atom. The query could be...
Code: Select all
DELETE FROM table_name WHERE age < 15 OR age > 30lolpix, your post made little sense to me.
I do understand how to query a mysql database and set conditions. My question is how can I design a method that will allow the user to specify different conditions and whether all of the conditions need to be met or only one, then delete any records that match the conditions set.
If I just use mysql_query() (which I think is what you were telling me to do?) in each of my applications and later on I want to start storing data in flat files I'd have to go through each application that used the mysql database and change how database operations are performed.
I do understand how to query a mysql database and set conditions. My question is how can I design a method that will allow the user to specify different conditions and whether all of the conditions need to be met or only one, then delete any records that match the conditions set.
If I just use mysql_query() (which I think is what you were telling me to do?) in each of my applications and later on I want to start storing data in flat files I'd have to go through each application that used the mysql database and change how database operations are performed.
What I mean, and I am not expert mind you, is that your database abstraction layer is one class with simple methods like fetch_row, fetch_array, query, etc.. Just the very basic and generic things that you require of a database transaction.
Next, you create another object which generates and validates query strings and a user interface to build them. This object would generate a form with the various options you want the user to be able choose, would check that all the information is legal, and then concatenate all of that into a standard SQL query and return that as a string.
The output from a query string object is then input into a generic query method of a database transaction object.
Next, you create another object which generates and validates query strings and a user interface to build them. This object would generate a form with the various options you want the user to be able choose, would check that all the information is legal, and then concatenate all of that into a standard SQL query and return that as a string.
The output from a query string object is then input into a generic query method of a database transaction object.
I should also mention Creole (php5) and ADOdb. No doubt there is something in PEAR as well but personally I avoid PEAR at all costs.
Eclipse is the only one I've any experience of. I've got a soft spot for it because my first encounter was one of those epiphany moments on my own learning curve - lean, tightly-factored "one class one task" classes provide an excellent example of how to write OOP code. Would be nice to update it for php5 one day (the new SPL grabs some class names eg).
Eclipse is the only one I've any experience of. I've got a soft spot for it because my first encounter was one of those epiphany moments on my own learning curve - lean, tightly-factored "one class one task" classes provide an excellent example of how to write OOP code. Would be nice to update it for php5 one day (the new SPL grabs some class names eg).
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany