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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.