★ wanayoo — archive 1999 http://fr.php.net/manual/fr/function.mysql-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  
<mysql_resultmysql_stat>
view the version of this page
Last updated: Sun, 20 Apr 2003

mysql_select_db

(PHP 3, PHP 4 )

mysql_select_db -- Sélectionne une base de données MySQL

Description

bool mysql_select_db ( string database_name [, resource link_identifier])

mysql_select_db() change la base de données active sur la connexion représentée par link_identifier. Si aucun identifiant n'est spécifié, la dernière connexion est utilisée. S'il n'y a pas de dernière connexion, la fonction tentera de se connecter seule, avec mysql_connect() et les paramètres par défaut.

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Toutes les requêtes suivantes avec mysql_query() seront faites avec la base de données active.

Voir aussi mysql_connect(), mysql_pconnect() et mysql_query().

Pour des raisons de compatibilité ascendante mysql_selectdb() est encore disponible. Elle est toutefois obsolète.



User Contributed Notes
mysql_select_db
add a note add a note
DEF2CEo${#]KK?]4@>
04-Jun-2003 04:57

Oromian at Hotmail offers some "favorite" code but it uses the deprecated mysql_db_query function and offers nothing to those looking for help with mysql_select_db().  Under mysql_db_query() is the following:

Note: This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db() and mysql_query() instead.

(email addr is ROT47 encoded)

alphalund at infinito dot it
06-May-2003 02:16

It seems that mySQL doesn't like the backtick (`) operator when changing DB.
So if you call
mysql_select_db('`some-db`',$link) ;
you will get an error.

However the same request will be successful if you delete backticks
mysql_select_db('some-db',$link);

Note that it's a mySql problem. The same problem appears if you try to do the same thing with a pure SQL statement:
USE DB `some-db`
won't Work! The bigger problem is that neither
USE DB some-db
will work because of the '-'

Oromian at hotmail dot com
30-Mar-2003 06:33

here is my favorite way to do the DB thang. :)

<?
// db variables
// inserts variables accordingly
$host = "";
$user = "";
$pass = "";
$db = "";
$table = "";

// connecting to the db
$link = mysql_connect ($host, $user, $pass);

// the db query
$q = "SELECT * from $table";
$results = mysql_db_query ($db, $q, $link);

// fetching the results
while ($row = mysql_fetch_array($result)){

echo "$row[whatever]
$row[whatever2]

";

}
/*

this is the area you can grab stuff from the db in the manner i did it above

whatever = name of the tables colum

*/

// closing the db link
mysql_close ($link);
?>

i'd be happy to answer some questions about this topic for you newbies our there, just drop me an email.

isox at chainsawbeer dot com
24-Feb-2003 05:05

Note that if the call to mysql_select_db() fails, mysql_errno() and mysql_error() are available with the error related information.
rhcubevn at netdoor dot com
29-Nov-2002 03:45

The previous post was a bad example.  Here is a better example, with the optional resource parm:

<?php
$connection = mysql_connect($host, $user, $pass);
$db = mysql_select_db($mydatabase, $connection);
?>

The second paremeter in mysql_select_db is if you defined more than one mysql_connect().  You should *always* define it, even if you only have one connection, as it is good practice, and will prevent confusion later if you want to add another connection.

P.S. The first part of my e-mail (before @) is rot_13 encoded!

Armond

jorik at scriptsnet dot nl
14-Sep-2002 05:44

<?PHP

mysql_connect("your host", "username", "password") or die(mysql_error());
mysql_select_db("your database") or die(mysql_error());

?>

add a note add a note

<mysql_resultmysql_stat>
 Last updated: Sun, 20 Apr 2003
show source | credits | stats | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Fri Jun 6 05:10:47 2003 CEST