Jump to content

Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T


adammm

Recommended Posts

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

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);

    }

}

?>

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"];  
?> 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.