Page 1 of 1

Please Advise - MySQL connection error

Posted: Wed Apr 29, 2009 2:11 pm
by danielwalters6
Here is the contents of frank.php

Code: Select all

<?php
$link = mysql_connect('xxx.xxx.xxx.xxx', 'uuuuuuuu', 'ppppppp');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Unfortunately, this is the output - what am I doing wrong? :(
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/fhlinux197/g/gadgetsolutions.co.uk/user/htdocs/frank.php on line 2

Re: Please Advise - MySQL connection error

Posted: Wed Apr 29, 2009 3:08 pm
by requinix
Since the error is on line two, and you censored line two...

Look at it. The error should be obvious.

Re: Please Advise - MySQL connection error

Posted: Wed Apr 29, 2009 4:44 pm
by danielwalters6
tasairis wrote:Since the error is on line two, and you censored line two...

Look at it. The error should be obvious.
Ppologies the censorship was performed by the administrator, I did put all of my details in the post by mistake.

I took the above (seemingly standard php script) substituted my SQL details and got the problem mentioned.
If the problem was obvious to me, I wouldn't post here and waste your time

Thankyou in advance for any support you can provide.

Re: Please Advise - MySQL connection error

Posted: Wed Apr 29, 2009 4:53 pm
by requinix
You aren't wasting anyone's time.

The code you have there, the censored version, is okay. There aren't any problems with it.
Take your real code, put it in tags, then preview your post. It will add highlighting to your code and you should be able to see something weird with it.

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 3:38 am
by danielwalters6
Hi tasairis,

Unfortunately nothing jumped out and grabbed me, claiming to be the problem.

Would it be possible for someone to actually try my code, with their own database values in, just to confirm it's correct.

Should the Database values be in the 'single quotes'

Code: Select all

mysql_connect('xxx.xxx.xxx.xxx', 'uuuuuuuu', 'ppppppp');
Thank you for your patience

dan

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 3:40 am
by Benjamin
Does your password have a ' in it?

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 4:23 am
by requinix
danielwalters6 wrote:Unfortunately nothing jumped out and grabbed me, claiming to be the problem.

Would it be possible for someone to actually try my code, with their own database values in, just to confirm it's correct.

Should the Database values be in the 'single quotes'

Code: Select all

mysql_connect('xxx.xxx.xxx.xxx', 'uuuuuuuu', 'ppppppp');
It could be that you don't know what to look for.

I ran your code through PHP's syntax checker before and it confirmed what I thought: no problems. So it must be in the censored part - the only (?) difference between your not-working code and the posted is-working code.

Single quotes are fine.

astions... huh, when did he become a mod... anyways, astions mentioned the only thing I can think of that's causing the problem: quotes in your username or password. If you had one in the password then the highlighting would look like

Code: Select all

mysql_connect('xxx.xxx.xxx.xxx', 'uuuuuuuu', 'ppp'pppp');
See how the coloring changes? That's what you would see. Except if I do that I get a generic "parse error" and not the T_BLAH message you have so it must be something else. Perhaps your code is more complicated and uses more than just a couple literal strings?

Finally, are you absolutely sure you're looking at the right line number in the right file?

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 8:58 am
by danielwalters6
Thank you for your continue support.

The output of frank.php can be seen here;
http://gadgetsolutions.co.uk/CMS/inc/frank.php

I have uploaded frank.php (I have had to zip it due to restrictions of this PHPBB installation)
frank.php.zip
Frank.php but with txt extension
(636 Bytes) Downloaded 13 times
Hopefully this might shed some light.

Looking at the frank.php you might see that I have not got MY personal details in. After putting my host's DB server IP, Username and Password, I'm getting the same result.
(Plus the output of an incorrect password etc, should be "error connecting to database" and not a parse error)

Thank you

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 1:58 pm
by requinix
You've got gibberish in your file.

Code: Select all

<?php
$link = mysql_connect('myhostipaddress' , 'username' , 'password' );
if (! $link) {
    die('Could not connect');
}
echo 'Connected successfully';
mysql_close($link);
?>
I believe those Âs mark spaces. Non-breaking spaces. Thing is, PHP doesn't like them.
Or if not the spaces it's the file encoding.

Either way, look in your editor for options to change that. Where? Don't know, depends on what you use.

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 7:30 pm
by danielwalters6
To edit my files, I was/am using TextWrangler, a free script-writing software package for Mac.

I have also re-written my files in Mac's own TextEdit (using Plain Text format) - re uploaded, with no significant difference.

Is it my FTP program that's uploading with the wrong encoding, I'm using Filezilla at the moment?

Can anyone suggest some Mac-friendly software which I could use to edit my php files?

Best regards.
dan.

Re: Please Advise - MySQL connection error

Posted: Thu Apr 30, 2009 11:20 pm
by Christopher

Re: Please Advise - MySQL connection error

Posted: Fri May 01, 2009 8:20 am
by danielwalters6
I dropped a question to my hosting provider, they pointed me to this script in their "knowledge base"

Code: Select all

<?php
$dblink = mysql_connect("databaseserver", "ursername", "password") or  die("Could not connect to MySQL server"); 
 
$db = mysql_select_db("gadgetsolu1") or die("Could not connect to Database"); 
 
$res = mysql_query("SHOW TABLES ") or die("Could not run query"); 
 
$row = mysql_fetch_array($res); 
 
if($row == "")
{ echo "No tables found, connection works.";}
else
{ echo "Tables found and connections work.<br />Tables found:<br />"; 
 foreach($row as $key => $value){ if(is_numeric($key)){ echo $value."<br />"; } } }?>
This seems to work. Although I can't seem to work out where it's Closing the database connection?