Jump to content

Unexpected Equal sign [Solved]


tet3828

Recommended Posts

I copied a php script from source forge. the support for the script is about as limited as my php knowledge is.

Im getting a parse error saying there is an unexpected equal sign in the second line of code here:

[code]
    function MySQL ($host,$dbUser,$dbPass,$dbName) {
        $this->mysql213.secureserver.net=$host;
        ............    /// <----- of course the user pass and name values go here.

}
[/code]

What is the problem here?
I tried putting "" around my server name and that just created a different error.
Thanks in advance. -treV
Link to comment
Share on other sites

[quote author=Hypnos link=topic=118671.msg485140#msg485140 date=1166141853]
Maybe you ment to put something like this...
$this->host = "mysql213.secureserver.net";

But it's hard to tell what you're trying to accoplish with only those 2 lines.
[/quote]

I really don't think it matters weather $host = myServer or myServer = $host

More solutions welcomed, thanks.
I can post more of the script but I don't think any of it is relevant to the error im recieving.
the script is from a pre-written shopping cart script.
Link to comment
Share on other sites

In this case, it [i]does[/i] matter. PHP is looking for the variable mysql213.secureserver.net as a child of $this, and trying to set it to the variable $host. I highly doubt that's what you're trying to do. Just give Hypnos's code a try; I bet you it'll solve the problem.
Link to comment
Share on other sites

[quote]the support for the script is about as limited as my php knowledge is[/quote]

So you admit that you know little about php, but you are able to tell when someone is incorrect without even testing what they said?

[quote]I really don't think it matters[/quote]

My money is on Hypnos' being correct:

[quote]Maybe you ment to put something like this...
$this->host = "mysql213.secureserver.net";[/quote]
Link to comment
Share on other sites

Im still stumped. Sorry for trying to correct those that know more than myself.
Im posting the script I am trying to modify. It was written by someone who has an entire page dedecaded writing a cart script so I would think he knows what he's doing. but I see what happened last time I thought....

This is most of the script he has in a zip file. maybe this will help solve some of my confusion:

Im starting to think that anywhere the author put "$this->" he intended for the script user remove "$this->" and input your data after it. But there was no help file with the script.

if anyone is really eager to investigat here is the link to the site that supplied the script:
http://www.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart

[code]
   function MySQL ($host,$dbUser,$dbPass,$dbName) {
        $this->host=$host;                         ///<----my host goes here
        $this->dbUser=$dbUser;                  ///<----my mySQL user name goes here
        $this->dbPass=$dbPass;                 ///<----my mySQL password here
        $this->dbName=$dbName;               ///<----my mySQL database name
        $this->connectToDb();                   ///<----I don't know what goes here
    }

    /**
    * Establishes connection to MySQL and selects a database
    * @return void
    * @access private
    */
    function connectToDb () {
        // Make connection to MySQL server
        if (!$this->dbConn = @mysql_connect($this->host,                 ///<----host again
                                      $this->dbUser,                               ///<----username again
                                      $this->dbPass)) {                            ///<----password again
            trigger_error('Could not connect to server');
            $this->connectError=true;                                         ///<----dont know what goes here
        // Select database
        } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) {                         
            trigger_error('Could not select database');
            $this->connectError=true;
        }
    }

    /**
    * Checks for MySQL errors
    * @return boolean
    * @access public
    */
    function isError () {
        if ( $this->connectError )                        ///<----????
            return true;
        $error=mysql_error ($this->dbConn);                           ///<----what does he want with the dbConn here?
        if ( empty ($error) )
            return false;
        else
            return true;
    }

    /**
    * Returns an instance of MySQLResult to fetch rows with
    * @param $sql string the database query to run
    * @return MySQLResult
    * @access public
    */
    function query($sql) {
        if (!$queryResource=mysql_query($sql,$this->dbConn))
            trigger_error ('Query failed: '.mysql_error($this->dbConn).
                           ' SQL: '.$sql);
        return new MySQLResult($this,$queryResource);                               ///<---what goes here?
    }
}

/**
* MySQLResult Data Fetching Class
* @access public
* @package SPLIB
*/
class MySQLResult {
    /**
    * Instance of MySQL providing database connection
    * @access private
    * @var MySQL
    */
    var $mysql;

    /**
    * Query resource
    * @access private
    * @var resource
    */
    var $query;

    /**
    * MySQLResult constructor
    * @param object mysql   (instance of MySQL class)
    * @param resource query (MySQL query resource)
    * @access public
    */
    function MySQLResult(& $mysql,$query) {
        $this->mysql=& $mysql;                             ///<----?????
        $this->query=$query;                                ///<----?????
    }

    /**
    * Fetches a row from the result
    * @return array
    * @access public
    */
    function fetch () {
        if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) {                        ///<----????
            return $row;
        } else if ( $this->size() > 0 ) {
            mysql_data_seek($this->query,0);
            return false;
        } else {
            return false;
        }
    }

    /**
    * Returns the number of rows selected
    * @return int
    * @access public
    */
    function size () {
        return mysql_num_rows($this->query);                                         ///<----????
    }

    /**
    * Returns the ID of the last row inserted
    * @return int
    * @access public
    */
    function insertID () {
        return mysql_insert_id($this->mysql->dbConn);
    }
   
    /**
    * Checks for MySQL errors
    * @return boolean
    * @access public
    */
    function isError () {
        return $this->mysql->isError();
    }
}
[/code]


WOW!
Link to comment
Share on other sites

You shouldn't have to worry about this part (the mysql class) of the script at all.  The global.inc.php file contains all of your connection credentials.

That class is correct.  The $this-> operator refers to the variable that is contained in that class...

[code]class MySQL {
    /**
    * MySQL server hostname
    * @access private
    * @var string
    */
    var $host;

    /**
    * MySQL username
    * @access private
    * @var string
    */
    var $dbUser;

    /**
    * MySQL user's password
    * @access private
    * @var string
    */
    var $dbPass;

    /**
    * Name of database to use
    * @access private
    * @var string
    */
    var $dbName;

    /**
    * MySQL Resource link identifier stored here
    * @access private
    * @var string
    */
    var $dbConn;

    /**
    * Stores error messages for connection errors
    * @access private
    * @var string
    */
    var $connectError;

    /**
    * MySQL constructor
    * @param string host (MySQL server hostname)
    * @param string dbUser (MySQL User Name)
    * @param string dbPass (MySQL User Password)
    * @param string dbName (Database to select)
    * @access public
    */
    function MySQL ($host,$dbUser,$dbPass,$dbName) {
        $this->host=$host;
        $this->dbUser=$dbUser;
        $this->dbPass=$dbPass;
        $this->dbName=$dbName;
        $this->connectToDb();
    }

    /**
    * Establishes connection to MySQL and selects a database
    * @return void
    * @access private
    */
    function connectToDb () {
        // Make connection to MySQL server
        if (!$this->dbConn = @mysql_connect($this->host,
                                      $this->dbUser,
                                      $this->dbPass)) {
            trigger_error('Could not connect to server');
            $this->connectError=true;
        // Select database
        } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) {
            trigger_error('Could not select database');
            $this->connectError=true;
        }
    }

    /**
    * Checks for MySQL errors
    * @return boolean
    * @access public
    */
    function isError () {
        if ( $this->connectError )
            return true;
        $error=mysql_error ($this->dbConn);
        if ( empty ($error) )
            return false;
        else
            return true;
    }

    /**
    * Returns an instance of MySQLResult to fetch rows with
    * @param $sql string the database query to run
    * @return MySQLResult
    * @access public
    */
    function query($sql) {
        if (!$queryResource=mysql_query($sql,$this->dbConn))
            trigger_error ('Query failed: '.mysql_error($this->dbConn).
                          ' SQL: '.$sql);
        return new MySQLResult($this,$queryResource);
    }
}[/code]

Notice at the top...the "var $host;" line.  When he writes "$this->host" from inside the class, it is refering to the value of that variable.
Link to comment
Share on other sites

I think I understand now. So I don't modify that file at all.. I modify this one


(global.inc.php):

[code]
<?php
$host = 'localhost';     
$user = 'root';
$pass = '';
$name = '';
$db = &new MySQL($host,$user,$pass,$name);
?>
[/code]

almost...[solved]
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.