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 ? Quote 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. Quote 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 ? Quote 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. Quote 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 ? Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/88822-creating-functions/#findComment-455970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.