adammm Posted August 14, 2008 Share Posted August 14, 2008 Hi, im pretty new to php and need some help :-\ im getting this error: " Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/p/h/y/phyz1kal/html/local/DbVars.php on line 9" <?php require_once("DbConnector.php"); // Include the database class $db = new DbConnector(); // Create an instance of the database class $db->connect(); // Connect to the database $query = "SELECT * FROM table; // Perform a query to the database $result = $db->query($query); $rows = $db->fetchArray($result); // Get an array with the results echo $rows["data"]; class Dbvars { var $settings; function getSettings() { // Database variables $settings['dbhost'] = 'localhost'; $settings['dbusername'] = '****'; $settings['dbpassword'] = '****'; $settings['dbname'] = '****'; return $settings; } } ?> can anyone please help me with this Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/ Share on other sites More sharing options...
trq Posted August 14, 2008 Share Posted August 14, 2008 $query = "SELECT * FROM table; Ought be.... $query = "SELECT * FROM table"; Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616270 Share on other sites More sharing options...
adammm Posted August 14, 2008 Author Share Posted August 14, 2008 now im getting Fatal error: Cannot instantiate non-existent class: dbconnector in /home/content/p/h/y/phyz1kal/html/local/DbVars.php on line 4 hmm weird Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616274 Share on other sites More sharing options...
Wolphie Posted August 14, 2008 Share Posted August 14, 2008 Post the code for DbConnector.php, it appears that the DbConnector class isn't defined. Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616275 Share on other sites More sharing options...
adammm Posted August 14, 2008 Author Share Posted August 14, 2008 heres the code for the dbconnector.php require_once 'DbVars.php'; <?php class DbConnector extends Dbvars { var $theQuery; var $link; var $dbname; var $host; var $user; var $pass; //*** Function: DbConnector, Purpose: Connect to the database *** function DbConnector(){ // Load settings from parent class $settings = Dbvars::getSettings(); // Get the main settings from the array we just loaded $this->host = $settings['dbhost']; $this->dbname = $settings['dbname']; $this->user = $settings['dbusername']; $this->pass = $settings['dbpassword']; } function setDatabase($ndbname) { $this->dbname = $ndbname; } function connect() { // Connect to the database $this->link = mysql_connect($this->host, $this->user, $this->pass)or die(mysql_error()); mysql_select_db($this->dbname); //register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; $res = mysql_query($query, $this->link)or die(mysql_error()); return $res; } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return mysql_fetch_array($result); } } ?> Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616278 Share on other sites More sharing options...
Wolphie Posted August 14, 2008 Share Posted August 14, 2008 Why is require_once 'DbVars.php'; placed outside of the <?php ?> tags? Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616282 Share on other sites More sharing options...
adammm Posted August 14, 2008 Author Share Posted August 14, 2008 no they were inside i deleted on accident and just typed them again, i guess outside, so the original code its inside. sorry Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616289 Share on other sites More sharing options...
Wolphie Posted August 14, 2008 Share Posted August 14, 2008 Ah, I've just realised. You've done the includes the wrong way around. Change DbConnector.php to [code=php:0] <?php class Dbvars { var $settings; function getSettings() { // Database variables $settings['dbhost'] = 'localhost'; $settings['dbusername'] = '****'; $settings['dbpassword'] = '****'; $settings['dbname'] = '****'; return $settings; } } class DbConnector extends Dbvars { var $theQuery; var $link; var $dbname; var $host; var $user; var $pass; //*** Function: DbConnector, Purpose: Connect to the database *** function DbConnector(){ // Load settings from parent class $settings = Dbvars::getSettings(); // Get the main settings from the array we just loaded $this->host = $settings['dbhost']; $this->dbname = $settings['dbname']; $this->user = $settings['dbusername']; $this->pass = $settings['dbpassword']; } function setDatabase($ndbname) { $this->dbname = $ndbname; } function connect() { // Connect to the database $this->link = mysql_connect($this->host, $this->user, $this->pass)or die(mysql_error()); mysql_select_db($this->dbname); //register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; $res = mysql_query($query, $this->link)or die(mysql_error()); return $res; } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return mysql_fetch_array($result); } } ?> Then as you would normally: <?php require_once("DbConnector.php"); // Include the database class $db = new DbConnector(); // Create an instance of the database class $db->connect(); // Connect to the database $query = "SELECT * FROM table; // Perform a query to the database $result = $db->query($query); $rows = $db->fetchArray($result); // Get an array with the results echo $rows["data"]; ?> Link to comment https://forums.phpfreaks.com/topic/119617-parse-error-parse-error-unexpected-expecting-t_string-or-t_variable-or-t/#findComment-616303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.