Thread: The SQL Class
View Single Post
Old 01-17-2009, 09:51 PM   #61 (permalink)
Tanax
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

Sorry. Didn't notice.

Quote:
It's not clear that this member actually means "database name" instead of some holder of data.
I don't know what others think, but it's a database class, and since the variable is grouped with host, user, and pass, it's pretty clear to me that it's the dbname.

Quote:
I'm unclear about getting everything set up and ready with this class. In order to get the ball rolling it appears one must first create an instance of this class, then explicitly call setHandler, then connect, then select (in that order only)? This feels like something to be done automatically in a constructor.
That's correct.
And that's because I've sometimes noticed that I wanted to set up the class before actually connecting, so that's why I've seperated them.
And yes, you have to call connect before the select, I think that's pretty obvious. You can't select the db when you haven't even connected.

I haven't heard anyone else say anything about this, but if it's a big problem, I could always change it.

Quote:
Suggest unsetting $this->pass after connecting
Good idea.

Quote:
Perhaps also call this method in a DBmysql::__destruct method to make sure it's always closed?
Now that I know that we will probably use a factory to allow different dbengine support, I can use the destruct now!

Quote:
Under what circumstances will this line get executed? Either $sql is NULL or not NULL.
Haha, ooops xD

Quote:
Why empty something you've just unset?
Just to be sure. Will it cause troubles?

Quote:
After this assignment, $sql will be either a "mysql result resource", TRUE or FALSE ... so why is this called $sql?
No. After that assignment $sql will always be a mysql result resource. What do you suggest it to be called then? I could change name to $query_result.

Quote:
Scenario:
1. Magic quotes is on: remove slashes from the string
2. Magic quotes is off: add slashes to the string

Given input "3 o' clock":
1. Magic quotes on means input is changed to "3 o\' clock" then we remove the slashes to make $secured "3 o' clock"
2. Magic quotes off means input isn't slashed ("3 o' clock") but we then add slashes to make $secured "3 o\' clock"

Result: different $secured values for the same input: that's not what we want.
Hmm, must've thought wrong. How would I do that then? Simply by removing the addslashes?

Quote:
Not 100% sure but if mysql_real_escape_string isn't available, I don't think mysql_escape_string will be available either. Just use mysql_real_escape_string.
But then again, you're not 100% sure, and it doesn't harm to keep it like it's now, unless you find out and become 100% sure

Quote:
Why are there so many places where one can provide a SQL query as an argument? I count 5.

There also appears to be a confusing selection of ways to achieve a usually simple task: grab an assoc. array of results. More clear documentation of the use of this class is requested (perhaps on the forums).
To make it more flexible. Sometimes you want to assign a sql statement, but not run it. Sometimes you want to run a query, but not get the result(for example when you're deleting a record. Sometimes you want to run a query and get the results. Obviously, you can achieve those by combining these.

Like:

$result = $db->loadQuery($sql)->exeQuery()->getQueryResult();

But, for those lazy people, I designed the exeQuery to accept an sql statement aswell, so it will loadQuery auto.

$result = $db->exeQuery($sql)->getQueryResult();


About the arrays, I wanted people to have as much "freedom" there.
Some people might want to load a fetched array, but not actually retrieve it until later. Some people might want to retrieve it at the same time.

So either, you execute a query before.

$db->exeQuery($sql); // or $db->loadQuery($sql)->exeQuery();
$fetch = $db->loadFetch(true)->getFetch();
// or $fetch = $db->getFetch(true, true);

Or, you execute the query WHILE fetching the array

$fetch = $db->loadFetch(true, $sql)->getFetch();
// or $fetch = $db->getFetch(true, true, $sql);

It's really simple. At least I think so. First parameter in loadFetch decides if it's assoc. True or false. Second parameter in loadFetch is the sql statement. Both of them are optional.
First parameter in getFetch is if you skipped the loadFetch function. True if you skipped it(so that it autoloads the fetch), false if you have it. Second parameter is the same as loadFetch's first parameter. Third parameter is the same as loadFetch's second parameter.
__________________
Tanax is offline  
Reply With Quote