You are on page 1of 7

23/9/2015

PHP: mysql_db_query - Manual

Downloads
Documentation
Get Involved
Help
Search

PHP 7.0.0 RC 3 Released


Getting Started
Introduction
A simple tutorial
Language Reference
Basic syntax
Types
Variables
Constants
Expressions
Operators
Control Structures
Functions
Classes and Objects
Namespaces
Errors
Exceptions
Generators
References Explained
Predefined Variables
Predefined Exceptions
Predefined Interfaces and Classes
Context options and parameters
Supported Protocols and Wrappers
Security
Introduction
General considerations
Installed as CGI binary
Installed as an Apache module
Filesystem Security
Database Security
Error Reporting
Using Register Globals
User Submitted Data
Magic Quotes
http://php.net/manual/es/function.mysql-db-query.php

1/7

23/9/2015

PHP: mysql_db_query - Manual

Hiding PHP
Keeping Current
Features
HTTP authentication with PHP
Cookies
Sessions
Dealing with XForms
Handling file uploads
Using remote files
Connection handling
Persistent Database Connections
Safe Mode
Command line usage
Garbage Collection
DTrace Dynamic Tracing
Function Reference
Affecting PHP's Behaviour
Audio Formats Manipulation
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Credit Card Processing
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
Keyboard Shortcuts
?
This help
http://php.net/manual/es/function.mysql-db-query.php

2/7

23/9/2015

PHP: mysql_db_query - Manual

j
Next menu item
k
Previous menu item
gp
Previous man page
gn
Next man page
G
Scroll to bottom
gg
Scroll to top
gh
Goto homepage
gs
Goto search
(current page)
/
Focus search box
mysql_drop_db
mysql_db_name
Manual de PHP
Referencia de funciones
Extensiones de bases de datos
Extensiones de bases de datos especficas del proveedor
MySQL
MySQL (Original)
Funciones de MySQL
Change language: Spanish
Edit Report a Bug

mysql_db_query
(PHP 4, PHP 5)
mysql_db_query Selecciona una base de datos y ejecuta una consulta sobre la misma
Advertencia
Esta funcin est obsoleta en PHP 5.3.0, por lo que ha sido eliminada, junto a la totalidad de la extensin original
de MySQL, en PHP 7.0.0. En su lugar, utilice las extensiones MySQLi o PDO_MySQL activamente
desarrolladas. Vase tambin la gua MySQL: elegir una API y sus P+F relacionadas para ms informacin. Las
alternativas a esta funcin son:
http://php.net/manual/es/function.mysql-db-query.php

3/7

23/9/2015

PHP: mysql_db_query - Manual

mysqli_select_db() y luego la consulta


PDO::__construct()

Descripcin
resource mysql_db_query ( string $database, string $query[, resource $link_identifier= NULL ] )
mysql_db_query() selecciona una base de datos y ejecuta una consulta en ella.

Parmetros
database

El nombre de la base de datos que va a ser seleccionada.


query

La consulta MySQL.
Los datos dentro de la consulta deben ser escapados apropiadamente.
link_identifier

La conexin MySQL. Si el identificador de enlace no se especifica, el ltimo enlace abierto por


mysql_connect() es asumido. Si no se encuentra dicho enlace, la funcin intentar establecer un nuevo
enlace como si mysql_connect() fuese invocado sin parmetros. Si no se encuentra o establece una
conexin, un error de nivel E_WARNINGes generado.

Valores devueltos
Devuelve un recurso de resultados de MySQL positivo al resultado de la consulta, o FALSEen caso de error. La
funcin tambin retorna TRUE/FALSEpara las consultas INSERT/UPDATE/DELETE indicando xito/fallo.

Historial de cambios
Versin
Descripcin
5.3.0
sta funcin ahora lanza ahora un aviso E_DEPRECATED.

Ejemplos
Ejemplo #1 Ejemplo alternativo de mysql_db_query()
<?php
if (!$enlace = mysql_connect('anfitrin_mysql', 'usuario_mysql', 'contrasea_mysql')) {
echo 'No pudo conectarse a mysql';
exit;
http://php.net/manual/es/function.mysql-db-query.php

4/7

23/9/2015

PHP: mysql_db_query - Manual

}
if (!mysql_select_db('nombre_bd_mysql', $enlace)) {
echo 'No pudo seleccionar la base de datos';
exit;
}
$sql

= 'SELECT foo FROM bar WHERE id = 42';

$resultado = mysql_query($sql, $enlace);


if (!$resultado) {
echo "Error de BD, no se pudo consultar la base de datos\n";
echo "Error MySQL: ' . mysql_error();
exit;
}
while ($fila = mysql_fetch_assoc($resultado)) {
echo $fila['foo'];
}
mysql_free_result($resultado);
?>

Notas
Nota:
Se ha de tener en cuenta que sta funcin NO vuelve a la base de datos a la que se estaba conectado
anteriormente. En otras palabras, no se puede utilizar sta funcin para ejecutar temporalmente una
consulta SQL en otra base de datos; se tendra que hacer el cambio manualmente. Se recomienda
encarecidamente usar la sintaxis basedatos.tabla en las consultas SQL o mysql_select_db() en lugar
de esta funcin.

Ver tambin
mysql_query() - Enviar una consulta MySQL
mysql_select_db() - Seleccionar una base de datos MySQL
add a note

User Contributed Notes


There are no user contributed notes for this page.
Funciones de MySQL
mysql_
affected_
rows
http://php.net/manual/es/function.mysql-db-query.php

5/7

23/9/2015

PHP: mysql_db_query - Manual

mysql_
client_
encoding
mysql_
close
mysql_
connect
mysql_
create_
db
mysql_
data_
seek
mysql_
db_
name
mysql_
db_
query
mysql_
drop_
db
mysql_
errno
mysql_
error
mysql_
escape_
string
mysql_
fetch_
array
mysql_
fetch_
assoc
mysql_
fetch_
field
mysql_
fetch_
lengths
mysql_
fetch_
object
mysql_
fetch_
row
mysql_
field_
flags
mysql_
field_
len
mysql_
field_
name
mysql_
field_
seek
mysql_
field_
table
mysql_
field_
type
mysql_
free_
result
mysql_
get_
client_
info
mysql_
get_
host_
info
mysql_
get_
proto_
info
mysql_
get_
server_
info
mysql_
info
mysql_
insert_
id
mysql_
list_
dbs
mysql_
list_
fields
mysql_
list_
processes
mysql_
list_
tables
mysql_
num_
fields
mysql_
num_
rows
mysql_
pconnect
mysql_
ping
mysql_
query
mysql_
real_
escape_
string
mysql_
result
mysql_
select_
db
mysql_
set_
charset
mysql_
stat
mysql_
tablename
mysql_
thread_
id
http://php.net/manual/es/function.mysql-db-query.php

6/7

23/9/2015

PHP: mysql_db_query - Manual

mysql_
unbuffered_
query
Copyright 2001-2015 The PHP Group
My PHP.net
Contact
Other PHP.net sites
Mirror sites
Privacy policy

http://php.net/manual/es/function.mysql-db-query.php

7/7

You might also like