RE: [PHP-DB] Don't know why query works this way
| From: | Aaron Wolski | Date: | Wed, 06 Aug 2003 12:23:23 +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-29725@lists.php.net to get a copy of this message | ||
>>>there are many ways to approach this.
one is, select the db before any of this activity with mysql_select_db
("dbname") then you can run as many queries against this database as you
want. Until you call that function again with another db name, mysql
with _always_ run against that database.
hth
jd
Since Jeff was telling him there were many ways to accomplish what he
wanted I figured I'd expand on what Jeff was saying and actually
ILLUSTRATE with working code/examples of what the 'many way's are.
Sorry if you found this to be Offtopic.
Aaron
-----Original Message-----
From: Adam Alkins [mailto:php@rasadam.com]
Sent: August 6, 2003 8:16 AM
To: Aaron Wolski
Cc: php-db@lists.php.net
Subject: RE: [PHP-DB] Don't know why query works this way
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