Foros del Web » Programando para Internet » PHP »

Extraño ayuda porfavor

Estas en el tema de Extraño ayuda porfavor en el foro de PHP en Foros del Web. Lo primero saludar y gracias por al menos leer este tema, a veces los errores de php son un poco "sosos" y devuelven cualquier cosa ...
  #1 (permalink)  
Antiguo 21/04/2009, 02:50
 
Fecha de Ingreso: diciembre-2007
Mensajes: 149
Antigüedad: 16 años, 4 meses
Puntos: 1
Extraño ayuda porfavor

Lo primero saludar y gracias por al menos leer este tema, a veces los errores de php son un poco "sosos" y devuelven cualquier cosa mi problema es que tengo unos scripts.

index.php
inicios.php
session.php

Pegare el código necesario a ver si me podeis ayudar, el resultado que m devuelve es:

Código HTML:
resource(6) of type (mysql link)       
      
resource(6) of type (Unknown) string(11) "basedatos_db" 
Warning: mysql_select_db(): 6 is not a valid MySQL-Link resource in /home/usuario/domains/dominio.com/public_html/admin/php/session.php on line 61
No se pudo usar esa base de datos basededatos_db  
Os explico tengo dos var_dump($conexion)

En el primero me imprime: resource(6) of type (mysql link)
En el segundo que pongo me imprime: resource(6) of type (Unknown)

Osea que una lineas mas arriba reconoce que es una variable de tipo mysql link pero unas lineas mas abajo sin yo haber usado $conexion ni nada dice que no reconoce el tipo (Unknown), y claro luego pues no puedo hacer la consulta con mysq_query porque no es del tipo mysql link.

No se que leches está pasando pero a mi me trae por el camino de la amargura y nose si alguno de vosotros me puede ayudar y hecharme un cable os dejo aquí los scripts y los metodo y tal que uso.

-- session.php --

Código PHP:
class Session
{
    
// Método crear conexion mysql
    
function crea_conexion($servidordb,$usuariodb,$contraseniadb)
    {
        
$this -> $servidordb $servidordb;
        
$this -> $usuariodb $usuariodb;
        
$this -> $contraseniadb $contraseniadb;
        
        
$conexion mysql_connect($servidordb,$usuariodb,$contraseniadb) or die( "Error conectando con base datos: server = $servidordb, usuario = $ussbd, contrase&ntilde;a = $contraseniad <br><br>".mysql_error());
        
$this -> $conexion $conexion;
        return 
$this -> $conexion;
    }

       
// Método que recupera los datos de un usuario
    
function ejecuta_sql($conexion,$basedatos,$sql)
    {
        
mysql_select_db($basedatos,$conexion) or die("No se pudo usar esa base de datos $basedatos ".mysql_error());
        
//$this -> colorea($sql);
        
echo $conexion;
        echo 
$basedatos;
        
$resultado mysql_query($sql,$conexion);
        
//$this -> colorea($resultado);
        
if($resultado)
        {
            
$filas mysql_num_rows($resultado);
            for(
$f=0;$f<$filas;$f++) // Navegando entre filas
            
{
                
$res[$f] = mysql_fetch_array($resultado);
            }
            return 
$res;
        }
        
//return mysql_fetch_array($resultado);
    
}

-- inicios.php --

Código PHP:
<?php 
    
require("admin/php/sql.php"); 
    require(
"admin/ewcfg6.php");
    require(
"admin/php/session.php"); 
?>
<?php
    $consulta 
= new Sql(); 
    
$index = new Session();
    
$conexion $index->crea_conexion(EW_CONN_HOST,EW_CONN_USER,EW_CONN_PASS);
    
var_dump($conexion); // primer var_dump que dige antes este si devuelve bien el tipo mysql link.
?>
-- index.php --

Código HTML:
<html>
<head>
<title>dominio.com</title>
<?php require("inicios.php") ?>
</head>
<body bgcolor="#ffffff">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="1046">
     <td width="12" height="46"><img name="index_r3_c1" src="partes_web/index_r3_c1.jpg" width="12" height="46" border="0" id="index_r3_c1" alt="" /></td>
    <td width="40" height="46"><img name="index_r3_c3" src="partes_web/index_r3_c3.jpg" width="40" height="46" border="0" id="index_r3_c3" alt="" /></td>
   <td width="320" height="46"><img name="index_r3_c4" src="partes_web/index_r3_c4.jpg" width="320" height="46" border="0" id="index_r3_c4" alt="" /></td>
   <td width="320" height="46"><img name="index_r3_c5" src="partes_web/index_r3_c5.jpg" width="12" height="46" border="0" id="index_r3_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="46" border="0" alt="" /></td>
  </tr>
  <tr>
   <td width="12" height="10"><img name="index_r4_c1" src="partes_web/index_r4_c1.jpg" width="12" height="10" border="0" id="index_r4_c1" alt="" /></td>
   <td width="662" height="10"><img name="index_r2_c2" src="partes_web/index_r4_c2.jpg" width="662" height="10" border="0" id="index_r2_c2" alt="" /></td>
   <td width="40" height="10"><img name="index_r4_c3" src="partes_web/index_r4_c3.jpg" width="40" height="10" border="0" id="index_r4_c3" alt="" /></td>
   <td width="320" height="10"><img name="index_r4_c4" src="partes_web/index_r4_c4.jpg" width="320" height="10" border="0" id="index_r4_c4" alt="" /></td>
   <td width="12" height="10"><img name="index_r4_c5" src="partes_web/index_r4_c5.jpg" width="12" height="10" border="0" id="index_r4_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="10" border="0" alt="" /></td>
  </tr>
  <tr>
   <td rowspan="6" width="12" height="641"><img name="index_r5_c1" src="partes_web/index_r5_c1.jpg" width="12" height="641" border="0" id="index_r5_c1" alt="" /></td>
   <td rowspan="6" width="662" height="641">
   <!-- CONTENIDO --> 
Código PHP:
<?php
        var_dump
($conexion); // Estee s el var dump que devuelve de tipo (Unknown), esta es mi duda de porque hace esto.
        
var_dump(EW_CONN_DB);
        if(
$_GET['cat'])
        {
            
$sql 'SELECT descripcion FROM categoria_portal WHERE id_categoria_portal = '.$_GET['cat'].'';
            
$texto     $index->ejecuta_sql($conexion,EW_CONN_DB,$sql);
            
//echo '<p>'.$texto[0]['descripcion'].'</p>';
        
}
        else if(
$_GET['subcat'])
        {
            
$sql 'SELECT descripcion FROM articulo_portal WHERE id_articulo_portal = '.$_GET['subcat'].'';
            
$texto$index->ejecuta_sql($conexion,EW_CONN_DB,$sql);
            echo 
'<p>'.$texto[0]['descripcion'].'</p>';
        }
        
/*else if($_GET['cat']=='reg')
        {
            $sql = 'SELECT descripcion FROM apuntate_portal WHERE id_apunt_portal = 1';
            $texto= $index->ejecuta_sql($conexion,EW_CONN_DB,$sql);
            echo '<p>'.$texto[0]['descripcion'].'</p>';
        }
        else
        {
            $sql = 'SELECT descripcion FROM inicio_portal WHERE id_ini_portal = 1';
            $texto= $index->ejecuta_sql($conexion,EW_CONN_DB,$sql);
            echo '<p>'.$texto[0]['descripcion'].'</p>';
        }*/
    
?>
Código HTML:
 <!-- #CONTENIDO --></td>
   <td rowspan="6" width="40" height="641"><img name="index_r5_c3" src="partes_web/index_r5_c3.jpg" width="40" height="641" border="0" id="index_r5_c3" alt="" /></td>
   <td width="320" height="165"><img name="index_r5_c4" src="partes_web/index_r5_c4.jpg" width="320" height="165" border="0" id="index_r5_c4" alt="" /></td>
   <td width="12" height="165"><img name="index_r5_c5" src="partes_web/index_r5_c5.jpg" width="12" height="165" border="0" id="index_r5_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="165" border="0" alt="" /></td>
  </tr>
  <tr>
   <td width="320" height="10"><img name="index_r6_c4" src="partes_web/index_r6_c4.jpg" width="320" height="10" border="0" id="index_r6_c4" alt="" /></td>
   <td width="12" height="10"><img name="index_r6_c5" src="partes_web/index_r6_c5.jpg" width="12" height="10" border="0" id="index_r6_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="10" border="0" alt="" /></td>
  </tr>
  <tr>
   <td width="320" height="165"><img name="index_r7_c4" src="partes_web/index_r7_c4.jpg" width="320" height="165" border="0" id="index_r7_c4" alt="" /></td>
   <td width="12" height="165"><img name="index_r7_c5" src="partes_web/index_r7_c5.jpg" width="12" height="165" border="0" id="index_r7_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="165" border="0" alt="" /></td>
  </tr>
  <tr>
   <td width="320" height="10"><img name="index_r8_c4" src="partes_web/index_r8_c4.jpg" width="320" height="10" border="0" id="index_r8_c4" alt="" /></td>
   <td width="12" height="10"><img name="index_r8_c5" src="partes_web/index_r8_c5.jpg" width="12" height="10" border="0" id="index_r8_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="10" border="0" alt="" /></td>
  </tr>
  <tr>
   <td width="320" height="165"><img name="index_r9_c4" src="partes_web/index_r9_c4.jpg" width="320" height="165" border="0" id="index_r9_c4" alt="" /></td>
   <td width="12" height="165"><img name="index_r9_c5" src="partes_web/index_r9_c5.jpg" width="12" height="165" border="0" id="index_r9_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="165" border="0" alt="" /></td>
  </tr>
  <tr>
   <td width="320" height="126"><img name="index_r10_c4" src="partes_web/index_r10_c4.jpg" width="320" height="126" border="0" id="index_r10_c4" alt="" /></td>
   <td width="12" height="126"><img name="index_r10_c5" src="partes_web/index_r10_c5.jpg" width="12" height="126" border="0" id="index_r10_c5" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="126" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="5" width="1046" height="9"><img name="index_r11_c1" src="partes_web/index_r11_c1.jpg" width="1046" height="9" border="0" id="index_r11_c1" alt="" /></td>
   <td><img src="partes_web/spacer.gif" width="1" height="9" border="0" alt="" /></td>
  </tr>
</table>
</body>
</html> 
Pues espero haberme explicado bien, me dedico a esto pero como siempre a vece todos necesitamos ayuda, espero vuestras respuesta gracis, a cualquier duda preguntad. Un saludo
  #2 (permalink)  
Antiguo 21/04/2009, 11:53
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Extraño ayuda porfavor

Cita:
Iniciado por sk1one Ver Mensaje
... a veces los errores de php son un poco "sosos" y devuelven cualquier cosa mi problema es que tengo unos scripts.
No, los errores de PHP y los de MySQL son bastante descriptivos
[/QUOTE]

Código:
// Resultado de echo $conexion; que no se donde ejecutas
resource(6) of type (mysql link)       

// Resultado de echo $conexion; y echo  $basedatos; en ejecuta_sql()
resource(6) of type (Unknown) string(11) "basedatos_db"

// PHP dice que la funcion mysql_select_db() no esta recibiendo un recurso valido de MySQL
Warning: mysql_select_db(): 6 is not a valid MySQL-Link resource in /home/usuario/domains/dominio.com/public_html/admin/php/session.php on line 61

// Resultado de OR DIE al seleccionar la base de datos
No se pudo usar esa base de datos basededatos_db

Ahora, lo que no entiendo es que si tienes $this->conexion recibas $conexion por parametro, cuando podria quedar asi:

Código php:
Ver original
  1. // Método que recupera los datos de un usuario
  2.     function ejecuta_sql($basedatos,$sql)
  3.     {
  4.         mysql_select_db($basedatos,$this->conexion) or die("No se pudo usar esa base de datos $basedatos");
  5.         //$this -> colorea($sql);
  6.         $resultado = mysql_query($sql,$conexion);
  7.         //$this -> colorea($resultado);
  8.         if($resultado)
  9.         {
  10.             $res = array(); // Tienes que inicializar la matriz
  11.             $filas = mysql_num_rows($resultado);
  12.             for($f=0;$f<$filas;$f++) // Navegando entre filas
  13.             {
  14.                 $res[$f] = mysql_fetch_array($resultado);
  15.             }
  16.             return $res;
  17.         }
  18.     }
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 27/04/2009, 02:13
 
Fecha de Ingreso: diciembre-2007
Mensajes: 149
Antigüedad: 16 años, 4 meses
Puntos: 1
Respuesta: Extraño ayuda porfavor

Cita:
Iniciado por Triby Ver Mensaje
No, los errores de PHP y los de MySQL son bastante descriptivos
Código:
// Resultado de echo $conexion; que no se donde ejecutas
resource(6) of type (mysql link)       

// Resultado de echo $conexion; y echo  $basedatos; en ejecuta_sql()
resource(6) of type (Unknown) string(11) "basedatos_db"

// PHP dice que la funcion mysql_select_db() no esta recibiendo un recurso valido de MySQL
Warning: mysql_select_db(): 6 is not a valid MySQL-Link resource in /home/usuario/domains/dominio.com/public_html/admin/php/session.php on line 61

// Resultado de OR DIE al seleccionar la base de datos
No se pudo usar esa base de datos basededatos_db

Ahora, lo que no entiendo es que si tienes $this->conexion recibas $conexion por parametro, cuando podria quedar asi:

Código php:
Ver original
  1. // Método que recupera los datos de un usuario
  2.     function ejecuta_sql($basedatos,$sql)
  3.     {
  4.         mysql_select_db($basedatos,$this->conexion) or die("No se pudo usar esa base de datos $basedatos");
  5.         //$this -> colorea($sql);
  6.         $resultado = mysql_query($sql,$conexion);
  7.         //$this -> colorea($resultado);
  8.         if($resultado)
  9.         {
  10.             $res = array(); // Tienes que inicializar la matriz
  11.             $filas = mysql_num_rows($resultado);
  12.             for($f=0;$f<$filas;$f++) // Navegando entre filas
  13.             {
  14.                 $res[$f] = mysql_fetch_array($resultado);
  15.             }
  16.             return $res;
  17.         }
  18.     }
[/QUOTE]

Porque en verdad no entiendo mucho la diferencia de this->$variable y llamarla $variable, tengo entendido que con this->$variable llamas a la avriable por su referencia en memoria.
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 00:55.