CHAMAVELI Posted December 22, 2008 Posted December 22, 2008 Ok my friend was helping me with mutliple database connections and made me an error handler, but anyway I am now getting this error while logging in: Parse error: syntax error, unexpected T_GLOBAL, expecting T_FUNCTION in /home/gangland/public_html/functions/db.php on line 4 Here is the code for the db.php file. Please do not steal this file (it won't work without the other section anyway). <? //db.php class db { global $error; var $conn; if(!isset($error)) { require_once('functions/error.php'); $error = new error(); } function connect($dbhost= 'localhost',$dbuser = 'root',$dbpass = '',$dbname = ''){ $conn = @mysql_connect($dbhost,$dbuser,$dbpass); $dbselect = @mysql_select_db($dbname,$conn); if(!$conn) return $error->db(mysql_error(),true,true); else if(!$dbselect) return $error->db(mysql_error(),true,true); else $this->conn = $conn; } function query($sql = ''){ $result = @mysql_query($sql,$this->conn); if(!$result) return $error->db(mysql_error(),true); else return $result; } function freeresult($result = ''){ $clear = @mysql_free_result($result); if(!$clear) return $error->db(mysql_error(),false); } function close(){ mysql_close($this->conn); } } ?> Quote
Haunted Dawg Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code Your line error is: var $conn; I am sure that the word "var" without a variable sign infront of it ($) would be javascript if i am not correct. How ever i see no need to use var $conn unless there is javascripting in the other section. Try this and see if anything goes wrong: <?php //db.php class db { global $error,$conn; if(!isset($error)) { require_once('functions/error.php'); $error = new error(); } function connect($dbhost= 'localhost',$dbuser = 'root',$dbpass = '',$dbname = '')} { global $conn,$error,$this; $conn = @mysql_connect($dbhost,$dbuser,$dbpass); $dbselect = @mysql_select_db($dbname,$conn); if(!$conn) { return $error->db(mysql_error(),true,true); } else if(!$dbselect) { return $error->db(mysql_error(),true,true); } else { $this->conn = $conn; } } function query($sql = '') { global $error,$this; $result = @mysql_query($sql,$this->conn); if(!$result) { return $error->db(mysql_error(),true); } else { return $result; } } function freeresult($result = '') { global $error; $clear = @mysql_free_result($result); if(!$clear) { return $error->db(mysql_error(),false); } } function close() { global $this; mysql_close($this->conn); } } ?> Quote
Decepti0n Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code Come on killah, you didn't even try there. You don't use 'global $anything' inside a class unless it's inside a function. 'var $conn' is correct and makes it a property (?) of the class Quote
Haunted Dawg Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code Meh.. i aint good with class's yet. hehe. But atleast worth a try! So what is the problem then? Quote
Haunted Dawg Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code Does he not need to use: public var = 'the var here in other words $conn'; so it would be: public $var = $conn; ------ Edit: I think i now know why. I have tried putting a function right after the class db { and i now get this error: Parse error: syntax error, unexpected T_VAR in /**/**/**/**/**.php on line 8 Quote
Decepti0n Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code Well yeah, I mean you can use var but you should be using public/private/protected. You wouldn't have 'public $var = $conn' though because it isn't defined, you'd just have 'public $conn = null;', then in the first function, set '$this->conn = mysql_connect() ... ' Quote
Haunted Dawg Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code Thank's for letting me know :) Quote
POG1 Posted December 22, 2008 Posted December 22, 2008 Re: Little help, I'm recieving an error from a custom code very good using clases but on the first few lines of it is where your going wrong. Try having everything inside the class wrapped in a function, so instead of getting a file on error posting an error message. There are many tutorials and examples on the internet which you can learn from/ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.