tet3828 Posted December 15, 2006 Share Posted December 15, 2006 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 Quote Link to comment Share on other sites More sharing options...
Hypnos Posted December 15, 2006 Share Posted December 15, 2006 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 Link to comment Share on other sites More sharing options...
tet3828 Posted December 15, 2006 Author Share Posted December 15, 2006 [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 = $hostMore 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. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 15, 2006 Share Posted December 15, 2006 i think the script is getting confused over the . and i to thought what Hypnos said... it would make more sense. can you search the document for maybe a variable named either 'mysql213.secureserver.net' or 'host'. i am betting you will find a host one... Quote Link to comment Share on other sites More sharing options...
Albright Posted December 15, 2006 Share Posted December 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 15, 2006 Share Posted December 15, 2006 [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] Quote Link to comment Share on other sites More sharing options...
tet3828 Posted December 15, 2006 Author Share Posted December 15, 2006 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! Quote Link to comment Share on other sites More sharing options...
Eric_Ryk Posted December 15, 2006 Share Posted December 15, 2006 Oh boy. Alright what you are looking at is a PHP class. What the author of the script has done is tried to make it easier on you.What you need to do is something like so:$mysql_db = new MySQL("host", "user", "pass", "db"); Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 15, 2006 Share Posted December 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
tet3828 Posted December 15, 2006 Author Share Posted December 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 15, 2006 Share Posted December 15, 2006 [quote]I modify this one(global.inc.php):[/quote]Yes..enter your information between the single quotes:[code]<?php$host = 'your_database_host_name'; $user = 'your_user_name';$pass = 'your_password';$name = 'the_database_name';$db = &new MySQL($host,$user,$pass,$name);?>[/code] Quote Link to comment Share on other sites More sharing options...
tet3828 Posted December 15, 2006 Author Share Posted December 15, 2006 yep that was it. wow it only took me 3 hours to figure out how to use someone elses script. thanx all. Quote Link to comment Share on other sites More sharing options...
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.