Re: Is select_db necessary?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"PJ" <af.gourmet@xxxxxxxxxxxx> wrote in message 
news:4A82AA58.2020806@xxxxxxxxxxxxxxx
> Paul M Foster wrote:
>> On Tue, Aug 11, 2009 at 08:23:21PM -0700, Allen McCabe wrote:
>>
>>
>>> I have seen different scripts for working with SQL, and most follow the 
>>> same
>>> method with on difference.
>>>
>>> Variables are defined (host, password, etc.)
>>> mysql_connect command
>>>
>>> //then, the difference
>>>
>>> mysql_select_db command
>>>
>>> //back to common
>>>
>>> $sql = "SELECT ... "
>>> $result = mysql_query($ql)
>>>
>>> Is the database selection necessary, or is that implied with a SELECT or
>>> other SQL command?
>>>
>>
>> All major SQL DBMSes can have multiple databases available. A given
>> database may contain a variety of tables. If you simply start firing SQL
>> commands at a DBMS, it won't know which database to look in unless you
>> tell it. By contrast, the connection process in PostgreSQL must include
>> a database; there is no separate database selection function call.
>>
>> Paul
>>
> I seem to recall from the manual, that once you have done mysql_connect
> , any subsequent queries will be directed at the same db until another
> mysql_connect points to another db. I repeat the call with every query
> as a precaution.
> I'm not expert, but I thought I'd offer my observation and am open to
> correction. ;-)
> PJ

This only works if you specify a database name in the call to 
mysqli_connect(). If provided (it is optional) it identifies the default 
database name for all subsequent queries. If, like me, you have multiple 
databases available, then you  need to use select_db in order to switch the 
default database from one to another.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux