Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Fatal error: Call to a member function getAll()

Estas en el tema de Fatal error: Call to a member function getAll() en el foro de PHP en Foros del Web. Buenas, tengo un problemilla haber si me ayudan Este es el problema : Código PHP: Fatal error :  Call to a member  function  getAll ()  on a non - object in C : ...
  #1 (permalink)  
Antiguo 24/05/2014, 08:20
 
Fecha de Ingreso: abril-2014
Mensajes: 26
Antigüedad: 10 años
Puntos: 0
Fatal error: Call to a member function getAll()

Buenas, tengo un problemilla haber si me ayudan

Este es el problema :


Código PHP:
Fatal errorCall to a member function getAll() on a non-object in C:xampphtdocsejemplo.comindex.php on line 47 

Esto es lo que intento hacer :

Poner un sistema de votos por estrellas (lo clásico xd)

dejare dos archivos: 1primero el del index.php y el 2segundo de la conexion...

1. primero : index.php

Código PHP:
<?php

if (version_compare(phpversion(), "5.3.0"">=")  == 1)
  
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
  
error_reporting(E_ALL & ~E_NOTICE); 
require_once(
'connections/conexionejemplo.php');


$sCode '';
$iItemId = (int)$_GET['id'];
if (
$iItemId) { // View item output
    
$aItemInfo $GLOBALS['MySQL']->getRow("SELECT * FROM `ejemplo` WHERE `id` = '{$iItemId}'"); // getting info about item from database
    
$sCode .= '<h1>'.$aItemInfo['title'].'</h1>';
    
$sCode .= '<h3>'.date('F j, Y'$aItemInfo['when']).'</h3>';
    
$sCode .= '<h2>Description:</h2>';
    
$sCode .= '<h3>'.$aItemInfo['description'].'</h3>';

    
// draw voting element
    
$iIconSize 64;
    
$iMax 5;
    
$iRate $aItemInfo['rate'];
    
$iRateCnt $aItemInfo['rate_count'];
    
$fRateAvg = ($iRate && $iRateCnt) ? $iRate $iRateCnt 0;
    
$iWidth $iIconSize*$iMax;
    
$iActiveWidth round($fRateAvg*($iMax $iWidth/$iMax 0));

    
$sVot '';
    for (
$i=$i<=$iMax $i++) {
        
$sVot .= '<a href="#" id="'.$i.'"><img class="votes_button" src="images/empty.gif" alt="" /></a>';
    }

    
$sVoting = <<<EOS
<div class="votes_main">
    <div class="votes_gray" style="width:
{$iWidth}px;">
        <div class="votes_buttons" id="
{$iItemId}" cnt="{$iRateCnt}" val="{$fRateAvg}">
            
{$sVot}
        </div>
        <div class="votes_active" style="width:
{$iActiveWidth}px;"></div>
    </div>
    <span><b>
{$iRateCnt}</b> votes</span>
</div>
EOS;

    
$sCode .= $sVoting;
    
$sCode .= '<h3><a href="'.$_SERVER['PHP_SELF'].'">back</a></h3>';
} else {
    
$sCode .= '<h1>List of items:</h1>';

    
$aItems $GLOBALS['MySQL']->getAll("SELECT * FROM `ejemplo` ORDER by `when` ASC"); // taking info about all items from database
    
foreach ($aItems as $i => $aItemInfo) {
        
$sCode .= '<h2><a href="'.$_SERVER['PHP_SELF'].'?id='.$aItemInfo['id'].'">'.$aItemInfo['title'].' item</a></h2>';
    }
}

?>
<!DOCTYPE html>
<html lang="en" >
    <head>
        <meta charset="utf-8" />
        <title>Creating own rate system</title>

        <link href="css/main.css" rel="stylesheet" type="text/css" />
        <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
    </head>
    <body>
        <div class="container">
            <?= $sCode ?>
        </div>
        
    </body>
</html>
2. segundo : conexionejemplo.php

Código PHP:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexionejemplo "localhost";
$database_conexionejemplo "ejemplo";
$username_conexionejemplo "root";
$password_conexionejemplo "";
$conexionwimne mysql_pconnect($hostname_conexionejemplo$username_conexionejemplo$password_conexionejemplo) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
Cita:
Estuve viendo en google el error y sale que es porque la conexion a la base de datos no esta definida, pues este codigo yo lo descarge de google y nose como hacerlo para que quede con el ejemplo...ayuda please!

Y si borro lo de las primeras lineas :

Código PHP:
<?php

if (version_compare(phpversion(), "5.3.0"">=")  == 1)
  
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
  
error_reporting(E_ALL & ~E_NOTICE); ?>
sale mas errores :

Código:
Notice: Undefined index: id in C:\xampp\htdocs\ejemplo.com\index.php on line 8

Notice: Undefined index: MySQL in C:\xampp\htdocs\ejemplo.com\index.php on line 47
  #2 (permalink)  
Antiguo 24/05/2014, 11:13
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 9 meses
Puntos: 379
Respuesta: Fatal error: Call to a member function getAll()

Código PHP:
Ver original
  1. $aItems = $GLOBALS['MySQL']->getAll("SELECT * FROM `ejemplo` ORDER by `when` ASC");
Asegurate que GLOBALS realmente tenga el objeto que esperas.
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #3 (permalink)  
Antiguo 24/05/2014, 14:03
 
Fecha de Ingreso: abril-2014
Mensajes: 26
Antigüedad: 10 años
Puntos: 0
Respuesta: Fatal error: Call to a member function getAll()

Cita:
Iniciado por hhs Ver Mensaje
Código PHP:
Ver original
  1. $aItems = $GLOBALS['MySQL']->getAll("SELECT * FROM `ejemplo` ORDER by `when` ASC");
Asegurate que GLOBALS realmente tenga el objeto que esperas.
e_e ese es el problema, que nose como hacerlo... en el post que encontre este codigo le falto poner un archivo mas que es el de la conexion a la BD... talves el puso mas cosas ahy... este es el link :

http://www.script-tutorials.com/how-to-create-own-voting-system/


EDITO :

Ya encontre el archivo faltante buscando en varios de sus temas... hubo uno en el que uso el mismo archivo, aki lo dejo por si acaso a alguien le sirva:

CMySQL.php


Código PHP:
<?php

class CMySQL {

    
// variables
    
var $sDbName;
    var 
$sDbUser;
    var 
$sDbPass;

    var 
$vLink;

    
// constructor
    
function CMySQL() {
        
$this->sDbName 'wimne';
        
$this->sDbUser 'root';
        
$this->sDbPass '';

        
// create db link
        
$this->vLink mysql_connect("localhost"$this->sDbUser$this->sDbPass);

        
//select the database
        
mysql_select_db($this->sDbName$this->vLink);

        
mysql_query("SET names UTF8");
    }

    
// return one value result
    
function getOne($query$index 0) {
        if (! 
$query)
            return 
false;
        
$res mysql_query($query);
        
$arr_res = array();
        if (
$res && mysql_num_rows($res))
            
$arr_res mysql_fetch_array($res);
        if (
count($arr_res))
            return 
$arr_res[$index];
        else
            return 
false;
    }

    
// executing sql
    
function res($query$error_checking true) {
        if(!
$query)
            return 
false;
        
$res mysql_query($query$this->vLink);
        if (!
$res)
            
$this->error('Database query error'false$query);
        return 
$res;
    }

    
// return table of records as result in pairs
    
function getPairs($query$sFieldKey$sFieldValue$arr_type MYSQL_ASSOC) {
        if (! 
$query)
            return array();

        
$res $this->res($query);
        
$arr_res = array();
        if (
$res) {
            while (
$row mysql_fetch_array($resMYSQL_ASSOC)) {
                
$arr_res[$row[$sFieldKey]] = $row[$sFieldValue];
            }
            
mysql_free_result($res);
        }
        return 
$arr_res;
    }

    
// return table of records as result
    
function getAll($query$arr_type MYSQL_ASSOC) {
        if (! 
$query)
            return array();

        if (
$arr_type != MYSQL_ASSOC && $arr_type != MYSQL_NUM && $arr_type != MYSQL_BOTH)
            
$arr_type MYSQL_ASSOC;

        
$res $this->res($query);
        
$arr_res = array();
        if (
$res) {
            while (
$row mysql_fetch_array($res$arr_type))
                
$arr_res[] = $row;
            
mysql_free_result($res);
        }
        return 
$arr_res;
    }

    
// return one row result
    
function getRow($query$arr_type MYSQL_ASSOC) {
        if(!
$query)
            return array();
        if(
$arr_type != MYSQL_ASSOC && $arr_type != MYSQL_NUM && $arr_type != MYSQL_BOTH)
            
$arr_type MYSQL_ASSOC;
        
$res $this->res ($query);
        
$arr_res = array();
        if(
$res && mysql_num_rows($res)) {
            
$arr_res mysql_fetch_array($res$arr_type);
            
mysql_free_result($res);
        }
        return 
$arr_res;
    }

    
// escape
    
function escape($s) {
        return 
mysql_real_escape_string(strip_tags($s));
    }

    
// get last id
    
function lastId() {
        return 
mysql_insert_id($this->vLink);
    }

    
// display errors
    
function error($text$isForceErrorChecking false$sSqlQuery '') {
        echo 
$text; exit;
    }
}

$GLOBALS['MySQL'] = new CMySQL();

Última edición por AprendizPollito; 24/05/2014 a las 15:25
  #4 (permalink)  
Antiguo 25/05/2014, 15:30
 
Fecha de Ingreso: noviembre-2007
Mensajes: 45
Antigüedad: 16 años, 5 meses
Puntos: 0
Respuesta: Fatal error: Call to a member function getAll()

Puede que la consulta esté mal. Asegúrate que el nombre de la tabla y la columna que estás consultado existan en tu BBDD.

Etiquetas: call, fatal, function, html, mysql, 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 07:00.