★ wanayoo — archive 1999 http://fr.php.net/manual/ru/function.mssql-select-db.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<mssql_rows_affectedmuscat>
view the version of this page
Last updated: Tue, 08 Mar 2005

mssql_select_db

(PHP 3, PHP 4 , PHP 5)

mssql_select_db -- Select MS SQL database

Description

bool mssql_select_db ( string database_name [, resource link_identifier] )

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

mssql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if mssql_connect() was called, and use it.

Every subsequent call to mssql_query() will be made on the active database.

In order to select a database containing a space or a hyphen ("-") you need to enclose the database name in brackets, like is shown in the example below:

Пример 1. mssql_select_db() example

<?php
   $conn
= mssql_connect('MYSQLSERVER', 'sa', 'password');
  
mssql_select_db('[my data-base]', $conn);
?>

See also: mssql_connect(), mssql_pconnect(), and mssql_query()



add a note add a note User Contributed Notes
mssql_select_db
bharris at spro dot net
16-Mar-2005 07:55
I had a weird issue with PEAR DB and the hang up was it's call to mssql_select_db.  The numbskull who set up the database I was working on called it 'primary'...not a good idea from an SQL perspective since it's part of the SQL syntax (primary key).  Trying to select primary as the DB resulted in an error returned as "No database selected" but the native error was "Incorrect syntax near the keyword 'primary'" which tipped me off. 

Enclosing the database name in square brackets ([primary]) fixed the issue.  Spent a few hours figuring this one out...hope it helps someone else.
david dot glass at brulines dot co dot uk
23-Nov-2001 03:36
Rather then use the sysobjects table to list all the tables, it is better to use the following query:

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
mark dot pearson at capitadbs dot co dot uk
23-Apr-2001 04:06
If you want to list the (user) tables
in a database after selecting it you
can use the following query, which is
the equivalent of mysql_list_tables():

SELECT name
FROM sysobjects
WHERE xtype = 'U'

<mssql_rows_affectedmuscat>
 Last updated: Tue, 08 Mar 2005
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Wed Mar 23 05:13:59 2005 CET