note 33639 deleted from function.mysql-connect by didou

From: Date: Wed, 02 Jul 2003 15:14:18 +0000
Subject: note 33639 deleted from function.mysql-connect by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-51371@lists.php.net to get a copy of this message
Note Submitter: carp_a_dieum@yahoo.com ---- To extend amn -at- frognet.net comment. Here is a cool example of reusing mssql connections and results. This works equally well on mysql connections. CAVET: I only used one db in this script. Start with standard security precautions... require "/some/dir/outside/web/dir/connection_parms.inc"; // includes system, user, dbpass, and database vars $db = @MSSQL_PCONNECT("$system", "$user", "$dbpass") || die ("Could not connect\n"); $sdb = @mssql_select_db("$database") || die ("<p>Could not select db</p>\n</body>\n</html>\n"); Construction your own $query array... $query=array('select'=>'*','table'=>'table_name', 'where'=>'','order'=>''); Make call to function... GetData($query,$results); where GetData would look something like... function GetData($query, &$results, &$errors) { /* ** query array contains: select, where, order ** defaults: '*','','' ** ** results pointer passed back to main page */ global $db, $sdb; if ($query['select']){ $select = $query['select']; } else { $select = '*'; } if ($query['table']){ $table = $query['table']; } else { $table = '*'; } if ($query['where']){ $where = $query['where']; } else { $where = ''; } if ($query['order']){ $order = $query['order']; } else { $order = ''; } if ($db) { $thisquery = "SELECT $select FROM $table $where $order"; $results = mssql_query($thisquery, $db); } } When $results is returned it can be reused to your heart's content, just remember to mssql_data_seek after each use. while ($output = mssql_fetch_array($results)) { echo "<p>".join("|",$output)."</p>\n"; } mssql_data_seek($results, 0); while ($output2 = mssql_fetch_array($results)) { echo "<p>".join("|",$output2)."</p>\n"; } ...

« previous php.notes (#51371) next »