0

Possible Duplicate:
Connecting to MySQL via SSL using PHP

Im new to php and I am not sure how to go about connecting to a database remotely using ssl. Using mysql workbench I am able to just enter the url of the database and the hostname and our password and select use ssl and I am able to connect. How can I do this using php?

4
  • 1
    What are you using here for database access? mysqli? PDO? Commented Dec 19, 2012 at 20:34
  • well then I vote down on stackoverflow's search algorithms Commented Dec 19, 2012 at 20:36
  • 2
    @user1809913 I used google :p Commented Dec 19, 2012 at 20:37
  • Eric Petroelje asked a question. Commented Dec 19, 2012 at 20:40

2 Answers 2

1

After a few preaprations on the mysql server side that are described here you can connect using ssl with the following php code:

$db = mysqlii_init();
$db->ssl_set('server-key.pem','server-cert.pem', 'cacert.pem', NULL, NULL);
$db->real_connct("your.server.net", "test", "testpass", "yourdb");

Or using the old (deprecated) mysql API this cn be done this way:

$link = mysql_connect("your.server.net", "test", "testpass", false, MYSQL_CLIENT_SSL) 
if(!$link) {
    die (mysql_error()));
}

Note:

Note that MySQL Native Driver does not support SSL before PHP 5.3.3, so calling this function when using MySQL Native Driver will result in an error. MySQL Native Driver is enabled by default on Microsoft Windows from PHP version 5.3 onwards.

Sign up to request clarification or add additional context in comments.

1 Comment

0

depends on what method you are trying to connect to mysql

$db = mysql_connect('your.server','username','pass',false,MYSQL_CLIENT_SSL);

however as of 5.5 mysql_connect is deprecated [the old connector is going away]

$db = mysqli::init();
$db->set_ssl($key,$cert,$ca,$capath,$cipher);
$db->real_connect($host,$username,$passwd,$dbname);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.