![]() |
The SQL Class
Hi!
Just thought I'd create a thread for the SQL class. This is what I have so far. Please come with suggestions or submit updated code if you feel that you wish to help out. php Code:
Howto use: PHP Code:
PHP Code:
Execute query: PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
A good class, but some revisions need to be made.
-Please use allman style indentation to conform to project standards. -For setHandler, do not use an array to pass paramaters, just pass multiple paramaters. -Have connect assign the connection to a variable so we can pass it to other functions that need database interactions. -Don't have it use a seperate function to set a query, just have the command functions accept a text parameter to the commend from. I work with a set command then execute it method in asp at work, its a pain. Those are all rather small things, other then what I named above, its a good class. |
Quote:
- I thought it would be better to have it an array, cause then you can assign the parameters at different locations. For example someone might want to process some data to decide which table to select(remember that this SQL class is actually a wide-use class, so it's not really designed specificly for THIS project). Trying to keep it general, so people can re-use it for other projects. But if it's neccessary, we can change that. - I'm not sure I follow. I have it assigned to $this->con, and I use it in other functions aswell. - As I said, I'm trying to make things general. Someone might want to assign a query, but not execute it before something has happend. However, to do what you want, I designed the exeQuery to accept an SQL statement, so to execute a query is simply done like this: PHP Code:
But that's me.. |
-Allman style
- I still think it would be best to have the parameters hard coded. -Misread that, never mind. -Thats not what I was saying. Looking at it agian, I'm not sure I understand all the code, what is the purpose of loadQuery? Sorry if I am being over-particular, I won't be like this once we get past the foundations of the script. |
Why use this over, for example, PDO or other currently available approaches?
|
Quote:
- Okey then, I'll edit that. - ^^ - To load a query, without having it executed. But you don't even need to use it, you can remove it from this class if you wish, however you need to change some stuff in the exeQuery then. Isn't it easier to just.. not use the loadQuery then? Np, we'll have a better end-script if we get a solid base. Quote:
|
For the last point, just leave it as is then.
|
Quote:
|
We won't use PDO because not all shared server have it. I want this application to be as stand alone as possible.
|
Quote:
|
Quote:
|
I mean plug and play. Since shared servers have virtually no flexibility, there are very few resources we can count on having. ImageGD is absolutely essential and almost everyone has it.
Since it will be an open source project made by volunteers, chances are that 99% of our users will be on a cheap shared server. Anyone willing to keep up a dedicated probably wouldn't go to a small corner of the internet for their script. |
Quote:
|
Yes, that is his job, but I am saying we are using GD because its required. PDO is not.
|
can we PLEASE stop using error suppression i.e. '@'
For one it slows down your script and secondly it makes it hard to debug and I for one can't be bothered grep'ing through the code for '@' every time something just blows up and no error is shown. For the production version, set error_reporting(0). |
Quote:
|
Quote:
|
As he said, error_reporting(0) will suppress them all.
I don't really care what you do for it, although it would be nice if you leave less for everyone during the optimization phase. |
Uhm, yea. If you want, I could remove them later.
I've updated the class now. Added new method: getRows, and also edited some of the old functions. Some simple howto's have been posted aswell. |
A lot of programmers are not fans of using exceptions to control the flow of the program. Most of your functions are using exceptions to exit out which is generally bad practice. Throw an exception when your program can not function.
For example, your secure function should be returning a true/false. It should also be a private function. Call the function in your exeQuery() method which would tell the exeQuery() method to finish execution. If it returns false the exeQuery() dosnt even execute the SQL query, and returns an empty dataset. |
| All times are GMT. The time now is 03:05 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0