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
Until you call that function again with another db name, mysql with
_always_ run against that database.


                      Michael Cortes                                                   
                      <[EMAIL PROTECTED]        To:       [EMAIL PROTECTED]            
            >                 cc:                                     
                                               Subject:  [PHP-DB] Don't know why query 
works this way                                   
                      08/05/2003 11:35                                                 
                      Please respond to                                                

I have been writing my queries like this.......

$link = mysql_connect ($host, $username, $password);
$query = "insert into $table ('joe', 15)";
if ( mysql_db_query($dbname, $query, $link))          {     }

But then I was reading that I should use mysl_query instead of
But I was having a problem with where do i put the $dbname.

When I used:

mysql_query ($dbname, $query, $link)

I got an error message saying i had too many arguments.  So I changed it

mysql_query ($query, $link)

I then got an error message saying it didn't know what database I was
connected to.  I finally got around the problem by including the database
name in the query, like so:

$query = "insert into $dbname.$table ('joe', 15)";

I shouldn't have to say, but this is a simplified example.  I didn't want
include all the fields, tables, values that the true example has.  The
question is, am I doing this right?  Do I have no choice but to retype the
$dbname all over the place if I want to use "mysql_query"?

Thank in advance for any help.


Michael Cortes
Fort LeBoeuf School District
34 East Ninth Street
PO Box 810
Waterford PA 16441-0810

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to