Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 04-18-2005, 04:13 PM   #1 (permalink)
ericanca
Registered User
 
Join Date: Apr 2005
Posts: 6
ericanca is on a distinguished road
Unhappy Help with outside connection to mysql using a php page

Hi all,
I am having a problem connecting to my "mySQL" server from a computer outside my network.

I have port forwarding setup to goto the right machine on port 3306
firewall allows port 3306 also gave firewall rights to mysqld-nt.exe.

I am running mysql on win 2003 server IIS and PHP
versions.... 4.0.22 mysql 4.3.10 PHP

I put in an IP addy instaed of localhost in the conf.inc.php file as database hostname.... here is the code in that file...
<?
$dbh=mysql_connect ("24.21.XX.XXX:3306", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("bytecon_baby");
?>

is this the right connection string? do I need to use a ODBC connection string? (ODbc is setup on the server for that database)

I am stummped.... do i need to give certain users authority to the database directory or the executable? I have given auth. to the internet guest account on these also.

Help please.
Eric
ericanca is offline   Reply With Quote
Old 04-18-2005, 07:25 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
the user needs to have rights to access the db from the remote address. as mysql root, you need to run a command something like this:
Code:
GRANT ALL ON bytecon_baby.* to user@1.2.3.4 identified by 'pass';
that is of course if the remote connection was coming from 1.2.3.4 .. if you wanted to allow any ip address to connect using that login, then use '%' as the ip.
Code:
GRANT ALL ON bytecon_baby.* to user@'%' identified by 'pass';
also, on your connect, you don't need :3306 after the ip address. that is the default mysql port and all you would need is the ip.
__________________
Mike
sde is offline   Reply With Quote
Old 04-18-2005, 08:49 PM   #3 (permalink)
ericanca
Registered User
 
Join Date: Apr 2005
Posts: 6
ericanca is on a distinguished road
I have done all that and still no good on the connection.....
I still get the same error....

grant rights to all ips for that user & database... took out the :3306 in the conf file...

left port forwarding on the router.

any other suggestions?
thanks,
Eric
ericanca is offline   Reply With Quote
Old 04-18-2005, 08:51 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
what does the die message say? can you ping the IP from outside?
__________________
Mike
sde is offline   Reply With Quote
Old 04-18-2005, 09:01 PM   #5 (permalink)
ericanca
Registered User
 
Join Date: Apr 2005
Posts: 6
ericanca is on a distinguished road
Warning: Can't connect to MySQL server on '24.21.98.121' (10060) in D:\Inetpub\temp\wwwroot\126176\aw384aw4\ewd\Questi onnaire\config.inc.php on line 2

Warning: MySQL Connection Failed: Can't connect to MySQL server on '24.21.98.121' (10060) in D:\Inetpub\temp\wwwroot\126176\aw384aw4\ewd\Questi onnaire\config.inc.php on line 2
I cannot connect to the database because: Can't connect to MySQL server on '24.21.98.121' (10060)

Yes i can ping this IP

Thanks
ericanca is offline   Reply With Quote
Old 04-18-2005, 09:18 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
well your mysql server can definately be reached from outside. you left your ip address in your reply so i tried to connect. i don't have a valid login, but it let me know 'access denied' which is a good sign. (1.2.3.4 is yoru ip, x.x.x.x is mine)
check it out:
Quote:
]$ mysql -h1.2.3.4 -uuser -p
Enter password:
ERROR 1045: Access denied for user: 'user@x.x.x.x' (Using password: YES)
are you sure there is not a firewall on the 'outside server' that is trying to call mysql? it seems like you should be getting the access denied error rather than the cannot connect to server.
__________________
Mike
sde is offline   Reply With Quote
Old 04-18-2005, 09:30 PM   #7 (permalink)
ericanca
Registered User
 
Join Date: Apr 2005
Posts: 6
ericanca is on a distinguished road
connected fine that way...

there is no firewall installed on the Win 2003 box serving Mysql
I used port forwarding for all calls to port 3306 in my netgear router to point to the IP of the win2003 server.

Firewall on outside server? you mean my win 2003 server?
not sure on that one.
Thanks,
E
ericanca is offline   Reply With Quote
Old 04-18-2005, 09:32 PM   #8 (permalink)
ericanca
Registered User
 
Join Date: Apr 2005
Posts: 6
ericanca is on a distinguished road
do you think the ISP may be blocking outbound port3306?
ericanca is offline   Reply With Quote
Old 04-18-2005, 09:35 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i mean on wherever your php scripts that are trying to connect to mysql are.

now, i just noticed something else, .. your mysql_select_db() should take a second argument, $dbh in this case.

try using this code for your connection. of course, replace the variables with your data:
PHP Code:
<?
$hostname
="localhost";
$mysql_login="myusername";
$mysql_password="mypassword";
$database="mydatabase";

// connect to the database server
if (!($db mysql_pconnect($hostname$mysql_login $mysql_password))){
  die(
"Can't connect to database server: ".mysql_error());    
}else{
  
// select a database
    
if (!(mysql_select_db("$database",$db))){
      die(
"Can't connect to database: ".mysql_error());
    }
}
?>
__________________
Mike
sde is offline   Reply With Quote
Old 04-18-2005, 09:37 PM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
Quote:
Originally Posted by ericanca
do you think the ISP may be blocking outbound port3306?
not likely since i was able to connect and get an 'access denied' error. that means that i was able to get to the mysql server to give me a response.
__________________
Mike
sde is offline   Reply With Quote
Old 07-19-2005, 10:15 AM   #11 (permalink)
DistantWords
Registered User
 
Join Date: Jul 2005
Posts: 1
DistantWords is on a distinguished road
I've been having this same problem, which is what brought me to this thread... And site...

I found one thing that might help. I was having the exact same problem as mentioned in this thread, but I figured something out. Sort of...

If you go into your mysql folder on the computer running MySQL, and go to the "bin" folder. Double click on "winmysqladmin.exe" (or at least that's what it's called for me..). There is a tab called "my.ini Setup". Click that tab.

You will see something that says:

#bind-address=*.*.*.*

(I blocked out the IP address)

Anyway, for me at least, the IP address that was there is different from my current IP address. So, I tried using that instead, and I at least got to the "denied" page instead of the flat out "can't connect" page.

However, here's the problem. The username is being displayed as "root@tricia-pc" (my computer's name) instead of "root@localhost", so I'm getting denied. I tried putting "root@localhost" as the username, but then it came up as "root@localhost@tricia-pc" isntead.

Is there any way to force the username to be "root@localhost"?

Did all that make sense?

Thanks,

Robert
DistantWords is offline   Reply With Quote
Old 07-19-2005, 10:33 AM   #12 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
Alter the grant settigns in your mysql access, to reflict your tricia-pc ie:
Code:
GRANT ALL ON <your database>.* to root@tricia-pc identified by 'pass';
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DAO wrapper class for Connection Pooling using JNDI Mazzman Java 4 03-29-2005 07:54 AM
WML PHP and MySQL rmill9681 PHP 10 11-20-2004 12:59 PM
Simple PHP MySQL code: confused. easilyi Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 10-24-2004 07:53 PM
cant connect to mysql databases using php eran PHP 11 08-07-2004 08:02 AM
Help with setting up mySQL and PHP Ilya020 PHP 11 03-19-2003 05:10 AM


All times are GMT -8. The time now is 05:03 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting