When I try to connect through the shell of the local machine at the remote MySQL server I can successfully connect:
> mysql -h remotehost -u myuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
But when I try to connect through a PHP script using
$serverName = "remotehost"; // here I put the actual IP address
$userName = "myuser";
$passCode = "actualpassword";
mysql_connect($serverName,$userName,$passCode);
I get the following error
Warning: mysql_connect(): Access denied for user 'myuser'@'localhost' (using password: YES)
The remote MySQL server version is 5.1.52 and the PHP version in the local machine is 5.3.10-1ubuntu3.4
I found a similar question but the answer does not solve my problem: problem connecting to remote mysql database using php
I'd really appreciate some help!
EDIT:
The output of php -i | grep "mysql"
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini
mysql
MYSQL_SOCKET => /var/run/mysqld/mysqld.sock
MYSQL_INCLUDE => -I/usr/include/mysql
MYSQL_LIBS => -L/usr/lib/i386-linux-gnu -lmysqlclient_r
mysql.allow_local_infile => On => On
mysql.allow_persistent => On => On
mysql.connect_timeout => 60 => 60
mysql.default_host => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysql.default_user => no value => no value
mysql.max_links => Unlimited => Unlimited
mysql.max_persistent => Unlimited => Unlimited
mysql.trace_mode => Off => Off
mysqli
MYSQLI_SOCKET => /var/run/mysqld/mysqld.sock
mysqli.allow_local_infile => On => On
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.reconnect => Off => Off
PDO drivers => mysql
pdo_mysql
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysql_code library? It was discontinued many years ago and removed entirely in PHP7. No new code should be written using this library. It leaves you vulnerable to SQL injection attacks (due to the lack of parameterised query support) and potentially other unpatched vulnerabilities. Switch to usingmysqliorPDOas soon as possible, and then learn how to write parameterised queries to protect your data from malicious input. See bobby-tables.com for a simple explanation of the risks and some sample PHP code to write queries safely.