Foros del Web » Programando para Internet » PHP »

Error: mysql_select_db() expects parameter 2 to be resource, object given

Estas en el tema de Error: mysql_select_db() expects parameter 2 to be resource, object given en el foro de PHP en Foros del Web. Que tal buenas tardes alguien podria ayudarme a descubrir cual es mi error por favor. <?php require_once('Connections/conexion.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, ...
  #1 (permalink)  
Antiguo 22/11/2015, 12:57
 
Fecha de Ingreso: noviembre-2015
Mensajes: 4
Antigüedad: 8 años, 5 meses
Puntos: 0
Error: mysql_select_db() expects parameter 2 to be resource, object given

Que tal buenas tardes alguien podria ayudarme a descubrir cual es mi error por favor.


<?php require_once('Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_conexion, $conexion);
$query_rsNombres = "SELECT * FROM cliente ORDER BY cliente.nombre";
$rsNombres = mysql_query($query_rsNombres, $conexion) or die(mysql_error());
$row_rsNombres = mysqli_fetch_assoc($rsNombres);
$totalRows_rsNombres = mysql_num_rows($rsNombres);
?>
<table width="371" border="1">
<tr>
<th width="55" bgcolor="#666666" scope="col">id_clave</th>
<th width="50" bgcolor="#666666" scope="col">nombre</th>
<th width="56" bgcolor="#666666" scope="col">apellido paterno</th>
<th width="56" bgcolor="#666666" scope="col">apellido materno</th>
<th width="60" bgcolor="#666666" scope="col">direccion</th>
<th width="54" bgcolor="#666666" scope="col">telefono</th>
</tr>
<tr>
<td><?php echo $row_rsNombres['id_cliente']; ?></td>
<td><?php echo $row_rsNombres['nombre']; ?></td>
<td><?php echo $row_rsNombres['ap']; ?></td>
<td><?php echo $row_rsNombres['am']; ?></td>
<td><?php echo $row_rsNombres['direccion']; ?></td>
<td><?php echo $row_rsNombres['telefono']; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>



Y esta es el codigo de conexion.

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexion = "localhost";
$database_conexion = "zapateria";
$username_conexion = "root";
$password_conexion = "";
$conexion = mysqli_connect($hostname_conexion, $username_conexion, $password_conexion) or trigger_error(mysql_error(),E_USER_ERROR);
?>
  #2 (permalink)  
Antiguo 22/11/2015, 13:11
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Error: mysql_select_db() expects parameter 2 to be resource, object given

Cita:
Que tal buenas tardes alguien podria ayudarme a descubrir cual es mi error por favor.
¿Piensas que somos algo así como adivinos y clarividentes o cómo?

Es bastante obvio, el error te dice que estás pasando un argumento mal a dicha función:
Cita:
Error: mysql_select_db() expects parameter 2 to be resource, object given
¿Por qué no lees en el manual cómo es que debes usar dicha función?

http://php.net/mysql_select_db

Así entiendes lo que sucede y nadie tiene que descubrir nada.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 22/11/2015, 14:18
 
Fecha de Ingreso: noviembre-2015
Mensajes: 4
Antigüedad: 8 años, 5 meses
Puntos: 0
Respuesta: Error: mysql_select_db() expects parameter 2 to be resource, object given

Que tal, una disculpa estoy empezando con PHP..
Si claro lei la documentacion y en mi codigo de conexion en mi linea me marca un error y me dice que ps proximamente estara en desuso y se eliminara pero aun asi me muestra la tabla que estoy haciendo, y bueno se que lo tengo que cambiar o por lo que lei a mysqli_connection:

$cn = mysql_pconnect($hostname_cn, $username_cn, $password_cn) or trigger_error(mysql_error(),E_USER_ERROR);

Mi problema es que al cambiarlo me marca el error que les mande y por mas que trato de corregirlo no puedo porque me marca errores aqui

mysql_select_db($database_conexion, $conexion);
$query_rsNombres = "SELECT * FROM cliente ORDER BY cliente.nombre";
$rsNombres = mysql_query($query_rsNombres, $conexion) or die(mysql_error());
$row_rsNombres = mysqli_fetch_assoc($rsNombres);
$totalRows_rsNombres = mysql_num_rows($rsNombres);

Y no entiendo que es lo que debo cambiar...
  #4 (permalink)  
Antiguo 22/11/2015, 14:58
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Error: mysql_select_db() expects parameter 2 to be resource, object given

A ver, estás mezclando funciones mysql_ con mysqli_ y claramente no son lo mismo.

Sólo debes leer con cuidado el manual, nada más.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #5 (permalink)  
Antiguo 30/11/2015, 21:18
 
Fecha de Ingreso: julio-2011
Ubicación: Los Rios
Mensajes: 145
Antigüedad: 12 años, 9 meses
Puntos: 10
Respuesta: Error: mysql_select_db() expects parameter 2 to be resource, object given

1.- El codigo que estas utilizando es uno generado por dreamweaver y al parecer intentas pasarlo a mysqli si lo dejas con mysql podrias empezar por borra la función GetSQLValueString que nunca la utilizas, limpiando asi el codigo:

en la linea de

Código PHP:
Ver original
  1. $row_rsNombres = mysqli_fetch_assoc($rsNombres);

dejala con mysql_fetch_assoc:
Código PHP:
Ver original
  1. $row_rsNombres = mysql_fetch_assoc($rsNombres);


y en tu archivo de conexion

Código PHP:
Ver original
  1. $conexion = mysql_pconnect($hostname_conexion, $username_conexion, $password_conexion) or trigger_error(mysql_error(),E_USER_ERROR);


en lugar de mysqli_conect

Parece que es todo.

Etiquetas: expects, mysql, object, parameter, resource, select, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:31.