php - Close session after executing database query -
i have little experience joomla , sql , appreciate help! using joomla 2.5 , querying data database , storing in memory following code:
function getlist() { $mainframe = jfactory::getapplication('site'); $db = jfactory::getdbo(); $query = " select * #__listuser $db->setquery( $query );" $rows = $db->loadobjectlist(); return $rows; } i have 3 questions,
- when query database, new db session opened, need close after or automatic?
- do know of more efficient way achieve method (a user session memory size 11mb!)
- is there security issue accessing database using method?
thank much! appreciated!
the code should (i don't see how can work now):
function getlist() { // $mainframe = jfactory::getapplication('site'); // don't need line! $db = jfactory::getdbo(); $query = " select * #__listuser 1=1"; // condition extract selected rows $db->setquery( $query ); // sets query , it's joomla, not sql. $rows = $db->loadobjectlist(); return $rows; } please note .... needs condition (else if want rows, remove , follows)
- you don't need close it
- 11mb not due query, try adding limit 0,1 (to return 1 row) you'll see memory doesn't change much. turn on debug in global configuration, , reload component. @ bottom of page you'll see extensions eating memory. 11mb acceptable though on installations.
- should create condition using input params, make sure $db->quote() values prevent sql-injection.
Comments
Post a Comment