| MOS 4.5 Database Class |
|
|
| Written by Arthur Konze | |
| Friday, 25 July 2003 | |
|
Mambo Open Source version 4.5 comes with a new and modified database engine. Therefore all developers should change their old scripts. As I develop myself I checked the new database class for you. Here is a small introduction how it will work on MOS 4.5: Preparing the database query The first thing is always to compile the SQL command. MOS 4.5 comes with a handy command which lets you compile your database query easy. The function setQuery of the database class prepares your query. You don't have to worry about table prefixes, the function will handle this for you if you use the substitute #__. The complete command looks like this: $database->setQuery("SELECT id, title, sectionid, catid FROM #__content"); Performing the database query To finaly execute the database query and maybe get back the results of your query, MOS comes with different functions, whether you await none, one or multiple results. Lets have a look: Query without result $database->setQuery("DELETE FROM #__categories WHERE id IN ($cids)"); While the first row prepares the query, the second line executes it and check's if everything went ok. If not, an error message is posted. Query with one result $database->setQuery("SELECT sum(hits) as count from #__stats_agents"); Query with multiple results $database->setQuery( "SELECT id, title FROM #__content"); The function will return NULL if the query fails. By default the array is indexed sequential, but you can hand over a key, which will then be used for indexing. No Warranty Surely you understand that I can give you no warranty of the code examples until the final version is released! |

