 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
12-30-2008, 10:55 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
The Config Class
UPDATE
Heres what I have so far in this config class:
LATEST
PHP Code:
class TalkPHP_Config {
// -- Public members -- // public static $configinfo = array();
// -- Private members -- // private $iSettingID;
private $sSettingname;
private $sSettingvalue;
// -- Protected members -- //
protected $dbobj;
// -- Deprecated // protected $query;
public function __construct($dbObj) {
if ( is_object($dbObj) && $dbObj instanceof DBMysql ) { $this->dbobj = $dbObj; } else throw new Exception( "Database Object failed, error called." );
self::grabOptions();
}
public function &option($optionname, $optionvalue) {
if ( isset($optionname) && isset($optionvalue) ) {
$this->sSettingname = $optionname; $this->sSettingvalue = $optionvalue;
} return false;
}
/** * Create Options * * @return boolean */ public function create($optionname, $optionvalue) { $this->sSettingname = $optionname; $this->sSettingvalue = $optionvalue; if ( isset($this->sSettingname) && isset($this->sSettingvalue) ) { $this->sSettingname = $this->dbobj->secure($this->sSettingname); $this->sSettingvalue = $this->dbobj->secure($this->sSettingvalue);
$this->dbobj->exeQuery("INSERT INTO `options` VALUES('','$this->sSettingname','$this->sSettingvalue');");
return true;
}
return false;
}
/** * Remove Options * * @return boolean */ public function remove($optionid) { $this->iSettingID = $optionid;
if ( is_numeric($this->iSettingID) ) { $this->dbobj->exeQuery("DELETE FROM `options` WHERE option_id = $this->iSettingID"); return true; }
return false; }
/** * Edit Options * * @return boolean */ public function edit() { if ( isset($this->sSettingname) && isset($this->sSettingvalue) ) { $this->sSettingname = $this->dbobj->secure($this->sSettingname); $this->sSettingvalue = $this->dbobj->secure($this->sSettingvalue); $name2id = self::Name2Id(); $this->dbobj->exeQuery("UPDATE `options` SET `option_name` = '$this->sSettingname', `option_value` = '$this->sSettingvalue' WHERE option_id = $name2id");
return true;
} return false; }
/** * Grab all the Options * */ private function grabOptions() { $options = $this->dbobj->exeQuery("SELECT option_id, option_name, option_value FROM `$this->table`");
if ( $options->rows() > 0 ) {
while ( $options->getFetch(false, true) ) { $this->configinfo["$options[option_name]"] = $options[option_value]; }
return true;
} return false;
}
/** * Converts the Name to the Id of the settings * * @return int */ private function Name2Id() {
if ( isset($this->sSettingname) ) { $this->sSettingname = $this->dbobj->secure($this->sSettingname);
$name2id = $this->dbobj->exeQuery("SELECT option_id, option_name FROM `$this->table` WHERE option_name = '$this->sSettingname'");
if ( $name2id->rows() > 0 ) { $name2id->getFetch(false, true);
return $name2id["option_id"]; }
} //else trigger_error( self::ERR_SETTINGS_NAME_EMPTY, E_USER_ERROR );
return false; }
}
__________________
VillageIdiot can have my babbies ;d
Last edited by Orc : 01-16-2009 at 05:03 AM.
|
|
|
|
12-30-2008, 11:30 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Outside of our PM convo (this will go for every coder).
Please code with allman style indents to conform with project standards.
Please do not use sprintf to secure queries, it is an unnecessary layer of processing that takes longer to do than just compiling the query.
|
|
|
|
12-30-2008, 11:31 PM
|
#3 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
Outside of our PM convo (this will go for every coder).
Please code with allman style indents to conform with project standards.
Please do not use sprintf to secure queries, it is an unnecessary layer of processing that takes longer to do than just compiling the query.
|
sprintf does not secure queries, Tanax's class secures the queries. :P sprintf formats the values in the query string.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-30-2008, 11:33 PM
|
#4 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by Orc
sprintf does not secure queries, Tanax's class secures the queries. :P sprintf formats the values in the query string.
|
Please don't use sprintf to format the query then; it's not necessary.
|
|
|
|
12-30-2008, 11:34 PM
|
#5 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
Please don't use sprintf to format the query then; it's not necessary.
|
How is it not? It makes it a ton easier.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-30-2008, 11:35 PM
|
#6 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by Orc
How is it not? It makes it a ton easier.
|
Sprintf takes longer to process, I don't see how it makes putting together a string a bit easier.
|
|
|
|
12-30-2008, 11:41 PM
|
#7 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
Sprintf takes longer to process, I don't see how it makes putting together a string a bit easier.
|
How long does it take to process? got a benchtest?
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-30-2008, 11:43 PM
|
#8 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
No, I have no bench marks. But calling a function will always take longer than using a standard operator. I'm sick of arguing with you about this, I could have almost written the class in the time I spend typing these messages. Do you want me to?
|
|
|
|
12-30-2008, 11:46 PM
|
#9 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
No, I have no bench marks. But calling a function will always take longer than using a standard operator. I'm sick of arguing with you about this, I could have almost written the class in the time I spend typing these messages. Do you want me to?
|
So why not allow it to take longer, it doesn't hurt :P
Not really, I'm taking the opportunity to do it, and you seem so strict at things.. You sound a bit arrogant. 
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-30-2008, 11:54 PM
|
#10 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by Orc
So why not allow it to take longer, it doesn't hurt :P
|
It doesn't help either. When given a choice between two methods, neither proposing any real advantage over the other, you pick the faster one.
Quote:
Originally Posted by Orc
Not really, I'm taking the opportunity to do it, and you seem so strict at things.. You sound a bit arrogant. 
|
I am trying to get standard procedure set up so our code looks the same across the script. Once we get basic things like that in place I won't be micro-managing people like I seem to be doing now.
As for being strict, I am only strict on general things like indentation and general structure. Once we get to smaller things, I wont care. I won't even look at the source most of the time when we move forward. However, when starting a project, what kind of project leader am I if I make no decisions? We saw where not being decisive got us for a month or so. I am sorry if I come across as arrogant, but I don't want to be asked for proof when I give a reason as simple as it takes longer (I'm always more compelled to answer "I'll do it, any particular reason you feel that way?" replies).
|
|
|
|
12-31-2008, 12:13 AM
|
#11 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Village Idiot
It doesn't help either. When given a choice between two methods, neither proposing any real advantage over the other, you pick the faster one.
I am trying to get standard procedure set up so our code looks the same across the script. Once we get basic things like that in place I won't be micro-managing people like I seem to be doing now.
As for being strict, I am only strict on general things like indentation and general structure. Once we get to smaller things, I wont care. I won't even look at the source most of the time when we move forward. However, when starting a project, what kind of project leader am I if I make no decisions? We saw where not being decisive got us for a month or so. I am sorry if I come across as arrogant, but I don't want to be asked for proof when I give a reason as simple as it takes longer (I'm always more compelled to answer "I'll do it, any particular reason you feel that way?" replies).
|
lol read pm
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-31-2008, 12:15 AM
|
#12 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Already replied to it.
I have decided to let the coders compile queries however they want, I will later review the code and see if they should be standardized. Now I have to finish packing for my trip, I may not be on till tomorrow morning where I will finalize my replacement.
|
|
|
|
12-31-2008, 02:03 AM
|
#13 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
PHP Code:
// -- I can't exactly understand Tanax's Class :/ -- // $this->configinfo = $this->dbobj ->exeQuery($this->queryformat) ->loadFetch(true,$this->queryformat);
You don't need to use $this->queryformat in your loadFetch if you've already executed the query with the exeQuery function.
Also, I think(since you're assigning the fetched results to a variable) you need to use the getFetch().
You could do like this:
PHP Code:
$this->configinfo = $this->dbobj ->exeQuery($this->queryformat) ->loadFetch(true)->getFetch();
or like this:
PHP Code:
$this->configinfo = $this->dbobj ->loadFetch(true,$this->queryformat)->getFetch();
or even like this:
PHP Code:
$this->configinfo = $this->dbobj ->getFetch(true, true, $this->queryformat); // 1st true is because you didn't use the loadFetch. // 2nd true is because you want assoc // 3rd parameter is the sql
Hope you understand more now. Read my SQL thread if not! Or PM me.
__________________
|
|
|
|
12-31-2008, 02:07 AM
|
#14 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Tanax
PHP Code:
// -- I can't exactly understand Tanax's Class :/ -- //
$this->configinfo = $this->dbobj
->exeQuery($this->queryformat)
->loadFetch(true,$this->queryformat);
You don't need to use $this->queryformat in your loadFetch if you've already executed the query with the exeQuery function.
Also, I think(since you're assigning the fetched results to a variable) you need to use the getFetch().
You could do like this:
PHP Code:
$this->configinfo = $this->dbobj
->exeQuery($this->queryformat)
->loadFetch(true)->getFetch();
or like this:
PHP Code:
$this->configinfo = $this->dbobj
->loadFetch(true,$this->queryformat)->getFetch();
or even like this:
PHP Code:
$this->configinfo = $this->dbobj
->getFetch(true, true, $this->queryformat);
// 1st true is because you didn't use the loadFetch.
// 2nd true is because you want assoc
// 3rd parameter is the sql
Hope you understand more now. Read my SQL thread if not! Or PM me.
|
I rewrote a lot of the code of my config class now so no need, plus you told me in a pm how to do it correctly. :P oh and you still haven't told me how to actually call the array elements. ;P
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-31-2008, 02:18 AM
|
#15 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
How do you mean? What array elements? How to use the array you've fetched?
Should be something like this:
PHP Code:
//The simple way of getting a fetch: $this->configinfo = $this->dbobj->getFetch(true, true, $this->queryformat);
//Check something, or whatever you want: if($this->configinfo['ActiveTemplate'] == 5) {
//Do something.. }
Should be like that!
__________________
|
|
|
|
12-31-2008, 02:22 AM
|
#16 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Tanax
How do you mean? What array elements? How to use the array you've fetched?
Should be something like this:
PHP Code:
//The simple way of getting a fetch:
$this->configinfo = $this->dbobj->getFetch(true, true, $this->queryformat);
//Check something, or whatever you want:
if($this->configinfo['ActiveTemplate'] == 5)
{
//Do something..
}
Should be like that!
|
Oh I see.. I'm stupid.. Nevermind.. Sigh..
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-31-2008, 02:24 AM
|
#17 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
One more thing though!
On your createConfig function, you set the SQL, but you don't execute it with the DB, is it supposed to be like that?
__________________
|
|
|
|
12-31-2008, 02:47 AM
|
#18 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Tanax
One more thing though!
On your createConfig function, you set the SQL, but you don't execute it with the DB, is it supposed to be like that?
|
I've removed createConfig function, and the othe config functions, cause it wasn't what Village Idiot wanted, so once I'm done with the new code, I'll update the op. sound good?
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
12-31-2008, 12:34 PM
|
#19 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Ah, I see. Great! 
__________________
|
|
|
|
01-16-2009, 04:23 AM
|
#20 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Updated (chars)
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|