ShaolinF Posted February 1, 2008 Share Posted February 1, 2008 Hi Guys, How would I create a function that interacts with a database? Would I need to create different functions for different statements (SELECT, UPDATE, INSERT etc) or would one function suffice ? Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/ Share on other sites More sharing options...
awpti Posted February 1, 2008 Share Posted February 1, 2008 Take a look at one of the many DB Abstraction libraries that exist. No need to reinvent the wheel. Other than that, yes, you would (logically) create a function per type. for example: $this->db->update(...) $this->db->insert(...) $this->db->getwhere(...) you know, unless you like creating one function with a bucketload of switch cases. That would be real perdy. Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/#findComment-454973 Share on other sites More sharing options...
ShaolinF Posted February 2, 2008 Author Share Posted February 2, 2008 Take a look at one of the many DB Abstraction libraries that exist. No need to reinvent the wheel. Other than that, yes, you would (logically) create a function per type. for example: $this->db->update(...) $this->db->insert(...) $this->db->getwhere(...) you know, unless you like creating one function with a bucketload of switch cases. That would be real perdy. Thanks. So is 'this->' referring to the db class ? In other words get the data between the parenthisis, process it in the update function found in the db class. Yes ? Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/#findComment-455804 Share on other sites More sharing options...
trq Posted February 2, 2008 Share Posted February 2, 2008 Yes, $this refers to the class that $this is within. Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/#findComment-455806 Share on other sites More sharing options...
ShaolinF Posted February 2, 2008 Author Share Posted February 2, 2008 Thanks, can you recommend me any libraries I could use ? Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/#findComment-455951 Share on other sites More sharing options...
toplay Posted February 2, 2008 Share Posted February 2, 2008 ADODB: http://adodb.sourceforge.net/ manual/tutorial at: http://phplens.com/lens/adodb/docs-adodb.htm ADODBLite: http://adodblite.sourceforge.net/index.php DB PEAR package: http://pear.php.net/package/DB Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/#findComment-455970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.