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 {
var $result;
function dbinit() {
$link = mysql_connect("localhost", "XX", "XX")
or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
mysql_select_db("XX");
}
function query($q){
$this->result = mysql_query($q, $link)
or die('counter SELECT error: '.mysql_errno().', '.mysql_error());
return $this->result;
}
}
class out extends admin {
var $sql;
$this->sql = 'select * from TABLE';
$this->dbinit();
$this->query($this->sql);
}
$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 {
var $result;
var $link;
function dbinit() {
$this->link = mysql_connect("localhost", "XX", "XX")
or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
mysql_select_db("XX");
}
function query($q){
$this->result = mysql_query($q, $this->link)
or die('counter SELECT error: '.mysql_errno().', '.mysql_error());
return $this->result;
}
}
Posted: Thu Feb 10, 2005 3:41 pm
by d3ad1ysp0rk
Try this:
Code: Select all
<?php
class admin {
var $link;
function dbinit() {
$this->link = mysql_connect("localhost", "XX", "XX") or die('counter CONNECT error: '.mysql_errno().', '.mysql_error());
mysql_select_db("XX");
}
function query($q){
$result = mysql_query($q, $this->link) or die('counter SELECT error: '.mysql_errno().', '.mysql_error());
return $result;
}
}
class out extends admin {
var $sql;
function out(){
$this->sql = "SELECT * FROM table";
$this->dbinit();
$result = $this->query($this->sql);
$my_array = array();
while($row = mysql_fetch_assoc($result)){
$my_array = $row;
}
return $my_array;
}
}
$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 {
var $sql;
function out(){
$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)){
$my_array = $row;
}
return $result;
}
}
$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 {
var $sql;
function get_out(){
$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)){
$my_array = $row;
}
return $my_array;
}
}
$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.