TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-31-2008, 12:49 PM   #21 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Not sure I understand what you mean with exceptions.

If the secure returns true or false, how would I then get the secured string from it? .. Sure I can secure $this->query_sql, but still..
It's a good idea though, I just need to know more about how to do it before I'll edit!
__________________
Tanax is offline  
Reply With Quote
Old 12-31-2008, 09:35 PM   #22 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 31
Thanks: 1
masfenix is on a distinguished road
Default

What I mean is that you are using exceptions to control the flow of your class which shouldnt be the case. You should only use exceptions when you want to throw an major error.

Infact you are doing the complete opposite of what exceptions are supposed to be doing:
Quote:
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
A very good example is the "new" keyword in c++. When you allocate memory in c++ you can wrap it in a try/catch block and catch the std::bad_alloc exception. In this case where memory can not be allocated, your program will probably end abrubtly (ie, if you dont catch the exception) and even if you catch the exception, its pretty much your chance to exit out gracefully.

Another very good example is divide by 0 exception..Another one is stackoverflow exception. When these things happen, your program just can not continue.

Code:
int *p 
try {
p = new int[25];
} catch (std::bad_alloc) {
}
In your case (the secure function for example) does not create a major error. You can handle in gracefully because its not an error. Imagine if you recieved a bad SQl query and everytime your program had to exit out because of it. You can simply prevent that by returning true/false and still keep the flow of your program.

Regarding your second concern about returning the new striing you have two choices:

1) modify the query that the class instance already holds. There's absoluetly no need to have a bad query in memory. The secure function should change the field to the new query and return true/false.

2) return empty string. Not as gracefull as true/false and I am not sure how PHP will parse an empty string in an if statement but its another option.
masfenix is offline  
Reply With Quote
Old 12-31-2008, 11:22 PM   #23 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I agree on the second concern. But how would I solve the first concern then? And does everyone else think that I shouldn't throw exceptions?
__________________
Tanax is offline  
Reply With Quote
Old 01-02-2009, 09:49 PM   #24 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I'm going away tomorrow to Florida for 10 days. Will be back the 13th, and back to business the 14th.

I will however, have internet there, so I might check out TalkPHP sometime.
Feel free to update the class if you're in desperate need of a fix!

See you!
__________________
Tanax is offline  
Reply With Quote
Old 01-14-2009, 02:31 PM   #25 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

How soon can you finish the SQL class, we need that asap.

And I stand corrected to masfenix, we probably should not use exceptions as I have instructed use.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-14-2009, 04:11 PM   #26 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Well, I can finish it whenever I get an answer about what exactly it is you want to be done.

As I've understood it, you want;

1. Have the secure function secure private $query_sql and return true or false.

2. Remove exceptions wherever they aren't needed; Which is exactly where, just to clarify?
__________________
Tanax is offline  
Reply With Quote
Old 01-14-2009, 11:10 PM   #27 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

1. Not exactly, I want a generic function the SQL cleans the variable passed in its parameter and returns it.
2. Exceptions are only needed in places where the program would otherwise crash, we probably don't need to use any right now. PHP is for the most part lenient, unlike most computer programming languages which are completely not.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-15-2009, 06:31 AM   #28 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

2. Okey! So I'll remove all the exceptions, and return false instead.

1. But that's how the function works right now? It cleans the variable passed in the parameter, and returns the cleaned variable?
__________________
Tanax is offline  
Reply With Quote
Old 01-15-2009, 04:50 PM   #29 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Then we are done for now, put the code into the SVN repository. We really need your class before any significant development can take place.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-16-2009, 04:46 AM   #30 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Another thing that would be good if you could change is the comments. Comment the purpose of the variable/function, but why restate the parameter list? Parameters are just as easy to read as is opposed to in a comment. What really needs to be commented is are the commands. I honestly had a hard time understanding a few parts of the class, comments on the purpose of that part of the code would have made things a lot easier.

I will establish a commenting convention in the next few days, but just stick to the theory that comments are made to state the non-obvious and nothing more.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-16-2009, 08:03 AM   #31 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Sure, I'll edit the exceptions, and that.
If you have a hard time understanding, read the first post in this thread for now, and I'll write more .. explaining comments later. Though, the parameters comes automaticly when I create a commentblock above my function in Zend, so that's why. And also I've seen other people use that, so I thought why not. I'll update the explaining part though.
__________________
Tanax is offline  
Reply With Quote
Old 01-16-2009, 09:02 AM   #32 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Class updated.

- Removed all exceptions
- Wrote alot of long comments to help you understand the class better
__________________
Tanax is offline  
Reply With Quote
Old 01-16-2009, 12:15 PM   #33 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

This probably sounds silly, or at best impractical, but how about having the ability to change the database driver that we're using? At the moment we're completely tied to the standard mysql_* but what if we wanted to use MySQLi or perhaps PDO with MySQL or SQLite?
Salathe is offline  
Reply With Quote
Old 01-16-2009, 12:26 PM   #34 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

A good suggestion. Should I add it like a prefix?

private $prefix;

And then have it assigned at the setHandler.
And a function to change, which would automaticly trigger the disconnect, then connect again using the new prefix ?

I'm not exactly sure if all the databases uses same commands cause I've only used Mysql.

Mysqli, do they have it like mysql_connect, but using mysqli instead of mysql: mysqli_connect ?
And how about query, and array, do they all use the same command, just a different prefix?
__________________
Tanax is offline  
Reply With Quote
Old 01-16-2009, 01:05 PM   #35 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Here are some of the relevant PHP Manual pages:
In brief, no they do not simply have the same function names with different prefixes. They take a more OO approach than the basic mysql_* functions.
Salathe is offline  
Reply With Quote
Old 01-16-2009, 02:29 PM   #36 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Okey, after reading about their functions, I see why you thought it would sound silly or impractical. Indeed, it would be very impractical to have mysqli option in the mysql DB object. However, I've done a DB factory class, which would let you create a db object based off of what db you want, like:

$db = DB::getDatabase('mysql');

and it would then create a new DBmysql and return the instance.
It would then be easy to create other objects, such as DBmysqli, DBmysql_PDO, DBsqlite_PDO, etc.

But that's only if you guys want it. However, I think Orc will have to change the __construct in his class since it's checking if the class is an instance of DBmysql, and I don't know if someone else has done something using this class that would be affected by this change.

I would however be happy to change it, if you want.
And by "change it", I mean create the factory class.
__________________
Tanax is offline  
Reply With Quote
Old 01-16-2009, 03:26 PM   #37 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I don't see a huge advantage to this, so I don't think we should modify that in right now. We need this class to get things moving, almost all of our further development requires database interaction. So I won't rule it out in the future, but a case will definitely have to be made to convince me it's a good idea.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-16-2009, 03:35 PM   #38 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

I think the class is done for now, could you svn it in?
__________________

Village Idiot is offline  
Reply With Quote
Old 01-16-2009, 06:25 PM   #39 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea sure! I'm just having troubles connecting to the SVN :S

In tortoise, I used the Repository Browser, and I checked:
http://code.google.com/p/talkphp/source/browse/

It just gives me this:
Quote:
Server sent unexpected return value (400 Bad Request) in response to OPTIONS request for http://code.google.com/p/talkphp/source/browse'
__________________
Tanax is offline  
Reply With Quote
Old 01-16-2009, 07:14 PM   #40 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Regarding the SVN problems, read http://code.google.com/p/talkphp/source/checkout for instructions except the path to Phlox is https://talkphp.googlecode.com/svn/phlox/trunk/

Kind of related to my previous posts, is this project indended to be a distributed software like Gallery or a centralised application like Flickr?
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 05:43 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design