Page 1 of 1

What is wrong in this? Error

Posted: Thu Feb 10, 2005 3:30 pm
by indianopendirectory
PLEASE HELP

CODE:

Code: Select all

<?php

class admin &#123; 
    var $result; 

function dbinit() &#123;
   $link = mysql_connect("localhost", "XX", "XX")
       or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
   mysql_select_db("XX");
&#125;

function query($q)&#123;

	$this->result = mysql_query($q, $link) 
    or die('counter SELECT error: '.mysql_errno().', '.mysql_error());

	return $this->result;
&#125;
&#125;

class out extends admin &#123;
var $sql;
$this->sql = 'select * from TABLE';
$this->dbinit();
$this->query($this->sql);

&#125;

$output = new out();
print ("$output");
?>
ERROR I AM GETTING:

Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in ............. on line 33

Posted: Thu Feb 10, 2005 3:34 pm
by d3ad1ysp0rk
Seeing as your code only shows 31 lines.. I have a feeling you didnt show us everything.
The first thing I saw, although not line 33, was this:

Code: Select all

$this->result = mysql_query($q, $link) or die('counter SELECT error: '.mysql_errno().', '.mysql_error());
It won't be able to access the $link variable seeing as it is only set inside the dbinit() function making it inassecible to other functions.

[edit]Also, to my knowledge, you can't just use commands inside of a class. They must be inside of a function.

Posted: Thu Feb 10, 2005 3:36 pm
by indianopendirectory
Sorry I did it, ERROR WAS ON line 24, Thanks for help

and I did some changes...

Code: Select all

class admin &#123; 
    var $result;
	var $link;

function dbinit() &#123;
   $this->link = mysql_connect("localhost", "XX", "XX")
       or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
   mysql_select_db("XX");
&#125;

function query($q)&#123;

	$this->result = mysql_query($q, $this->link) 
    or die('counter SELECT error: '.mysql_errno().', '.mysql_error());

	return $this->result;
&#125;
&#125;

Posted: Thu Feb 10, 2005 3:41 pm
by d3ad1ysp0rk
Try this:

Code: Select all

<?php
class admin &#123;
    var $link;
    function dbinit() &#123;
        $this->link = mysql_connect("localhost", "XX", "XX") or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
        mysql_select_db("XX");
    &#125;

    function query($q)&#123;
        $result = mysql_query($q, $this->link) or die('counter SELECT error: '.mysql_errno().', '.mysql_error());
        return $result;
    &#125;
&#125;

class out extends admin &#123;
    var $sql;
    function out()&#123;
        $this->sql = "SELECT * FROM table";
        $this->dbinit();
        $result = $this->query($this->sql);
        $my_array = array();
        while($row = mysql_fetch_assoc($result))&#123;
            $my_array = $row;
        &#125;
        return $my_array;
    &#125;
&#125;

$output = new out();
print_r($output);
?>
I think that's what you were trying to do at least..

Posted: Thu Feb 10, 2005 3:49 pm
by indianopendirectory
Used your code , Now getting

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in ...... on line 10
counter SELECT error: 0,

10 th LINE is

Code: Select all

$result = mysql_query($q, $link) or die('counter SELECT error: '.mysql_errno().', '.mysql_error());
Many Thanks :)

Posted: Thu Feb 10, 2005 3:52 pm
by d3ad1ysp0rk
try mine again, I edited it like a second after I posted it and was afraid you'd copy the original. :p

Posted: Thu Feb 10, 2005 4:28 pm
by indianopendirectory
Yes it's working but not fetching record (only one record, in phpMyAdmin, sql working fine)

Code: Select all

class out extends admin &#123; 
    var $sql; 
    function out()&#123; 
        $this->sql = "SELECT iod_l1_st.cat FROM iod_l1_st where iod_l1_st.parent = 'l0_root'"; 
        $this->dbinit(); 
        $result = $this->query($this->sql); 
        $my_array = array(); 
        while($row = mysql_fetch_assoc($result))&#123; 
            $my_array = $row; 
        &#125;  
        return $result; 
    &#125; 
&#125; 

$output = new out(); 
echo("Output = $output");
Result =
Output : Object

Posted: Thu Feb 10, 2005 4:41 pm
by d3ad1ysp0rk
My apologies :)

Code: Select all

class out extends admin &#123;
    var $sql;
    function get_out()&#123;
        $this->sql = "SELECT iod_l1_st.cat FROM iod_l1_st where iod_l1_st.parent = 'l0_root'";
        $this->dbinit();
        $result = $this->query($this->sql);
        $my_array = array();
        while($row = mysql_fetch_assoc($result))&#123;
            $my_array = $row;
        &#125; 
        return $my_array;
    &#125;
&#125;

$newobj = new out();
print_r($newobj->get_out);
Should work.

Posted: Fri Feb 11, 2005 1:46 am
by indianopendirectory
:) I will try this, Thanks for your every support. Many Thanks.