Page 1 of 1

php couldnt connect to mysql

Posted: Thu Jun 03, 2010 3:58 pm
by Abyssal
hello there.

i have a problem with my website. i try to add top pvp / top pk but i cant because php doesnt connect to mysql. here is my config files:

stats.php:

Code: Select all

<?php     $db_user = "root";     $db_pass = "my password here";     $db_name = "l2jdb";     $db_serv = "my ip here";      $res = mysql_connect ( $db_serv, $db_user, $db_pass ) or die ("Coudn't connect to [$db_serv]");     $resdb = mysql_select_db ( "$db_name",$res );      return $res;  ?>
status.php
<?php
$server = "my ip here";
$portg = "7777";
$portl = "2106";
$timeout = "1";
?>

i use this website:

http://www.maxcheaters.com/forum/index. ... c=115992.0

i use freehostia and my server is dedicated. ive also enabled the mysql remote access in my server machine and ive opened the ports 80 and 8000.

i just hope somebody is going to answer because i know there are only a few people really willing to help newbies. so im almost sure the only post in this topic will be mine.

Re: php couldnt connect to mysql

Posted: Fri Jun 04, 2010 12:37 pm
by Abyssal
of course nobody answering as always. but this time i will keep replying until you answer because you ve never helped me like i wanted in this forum.

Re: php couldnt connect to mysql

Posted: Fri Jun 04, 2010 1:03 pm
by JIV
and what? this is php forum? why dont you ask person who made it?

Re: php couldnt connect to mysql

Posted: Sun Jun 06, 2010 2:30 am
by UnAfraid
You cant use return because it can be used in function only and $res will return an object if successfully connected to mysql server on fail will return false.
take a look on this http://php.net/mysql_connect
and try this

Code: Select all

 <?php     $db_user = "root";     $db_pass = "my password here";     $db_name = "l2jdb";     $db_serv = "my ip here";      $res = mysql_connect ($db_serv, $db_user, $db_pass);    $resdb = mysql_select_db ($db_name, $res);     if (!$res || !$resdb)        die(mysql_error());?>
if you use root user it will not work because it is limited to work on localhost you need to create a new user and give him access to connect from remote ip i think thats your problem.

if that's your problem try this

Code: Select all

CREATE USER 'myname'@'remote.server.address' IDENTIFIED BY 'mypass';GRANT ALL PRIVILEGES ON l2jdb.* to 'myname'@'remote.server.address';FLUSH PRIVILEGES;

Re: php couldnt connect to mysql

Posted: Sun Jun 06, 2010 1:31 pm
by Abyssal
no its ok the problem is i opened the wrong port. i hadnt open the mysql port. i solved it :)