Link to home
Start Free TrialLog in
Avatar of novocent
novocent

asked on

How do I connect from php to mySQL using SSL?

How do I make a connection from a php script to a mysql database using SLL to encrypt the transferred data?
Avatar of mgrennan
mgrennan
Flag of United States of America image

This is a simple example.

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

See http://us.php.net/function.mysql-connect
Where are the PHP and MySQL hosts (what URLs)?
Avatar of novocent
novocent

ASKER

mgrennan, I want to connect via SSL to secure the transfer of data between the php server and the mysql server. The mysql server is on a remote host.
SOLUTION
Avatar of mgrennan
mgrennan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mgrennan, I will look into that info. I started to make and installed certificates earlier today, but never completed the process. I came across another idea and it seemed to work. I was hoping to confirm the solution: I used this connection:
$conn = mysql_connect("XXX.XXX.XXX.XXXX", "username", "password",true, MYSQL_CLIENT_SSL);
on the remote mysql database I used:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'remoteIP' IDENTIFIED BY 'password' REQUIRE SSL;
It made a connection which I think is SSL, I know of no way to confirm that. I do know that trying to use only $conn = mysql_connect("XXX.XXX.XXX.XXXX", "username", "password") fails. It seemed so simple that I was doubting the SSL connection. And doubting whether the information transferred from the mysql database to the remote php was actually encrypted.  Any thoughts?



ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial