RE: [PHP-DB] Don't know why query works this way

From: Date: Wed, 06 Aug 2003 12:16:28 +0000
Subject: RE: [PHP-DB] Don't know why query works this way
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-29724@lists.php.net to get a copy of this message
Quoting Aaron Wolski <aaronjw@martekbiz.com>: > Here's some functions I use in my development which save on connect and > query calls for me. > > //General Purpose Utilities. > //db_connect connects to the database server and selects the proper > database. > //Arguments: None > //Returns: Nothing > > > function db_connect() { > > mysql_pconnect("localhost","username","password"); > mysql_select_db("Database"); > > } > > > //db_query queries the database server and returns the results. > //Arguments: SQL query string > //Returns: Query results > > function db_query($query) { > > return mysql_query($query); > > } > > > //db_fetch returns the next set of results from a db_query. > //Arguments: db_query results variable > //Returns: Next set of query results as an array or 0 if no further > results are present > > > function db_fetch($results) { > > return mysql_fetch_array($results); > > } > > > //db_numrows returns the number of rows selected from a query. > //Arguments: query result > //Returns: number of rows in the query result > > function db_numrows($result) { > > return mysql_num_rows($result); > > } > > > //Always connect to the database! > > db_connect(); > > > Keep these in an include file. The db_connect(); goes at the bottom and > keep the connection open during the routines. > > > To call db_query you would use it like: > > $someQuery = db_query("SELECT * from someTable ...."); > > > to get the results out of the query you would call db_fetch and use it > like: > > > $someResult = db_fetch($someQuery); > > If you needed to return an array you would use it with a while or for > statement like: > > While ($someResult = db_fetch($someQuery)) { > > } > > If you needed to get the number of rows from the query you'd use like: > > numRows = db_numrows($someQuery); > > or > > if (db_numrows($someQuery) > ...) > > > These are just some thing I use to make my life easier. > > Hope it helps > Not to be rude... but what does that have to do with his question? -- Adam Alkins http://www.rasadam.com

« previous php.db (#29724) next »