In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> 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 mysql_db_query.  
> 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 to:
> 
> 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 to 
> 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.

Well, no. You need to do mysql_select_db to select a database up front and 
if you happen to need to change databases, use it again. So something like

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

etc etc
-- 
Quod subigo farinam

$email =~ s/oz$/au/o;
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to