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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is a simple example.

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

Ray PaseurCommented:
Where are the PHP and MySQL hosts (what URLs)?
novocentAuthor Commented:
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.
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

So this must be a remote connections.  Setting up SSL with MySQL is a completed process involving creating and installing certificates.

Maybe your best best is to tunnel over ssh.  A command line:

ssh -L 3306:mysqlhsot:3306 -l user -N mysqlhost

Your application would then connect to localhost port 3306 and would be ssl connected to port 3306 on the remote server.
Here is the information on connect PHP with a certificate.

Here is the information on setting up MySQL certificates.\
novocentAuthor Commented:
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:
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?

Sounds like you have it work.  MYSQL_CLIENT_SSL is a good function.

Use WireShark to confirm the connection is encrypted.

Wireshark is a great tool and you should learn how to use it.  The trick to using it in this case is to use a filter to see only the connections between your guest and server.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.