Jump to content

Connect to a mySQL DB over SSL


bschultz

Recommended Posts

I'm having a hard time getting this to work.  I've followed the step from the MySQL manual on how to generate and save the certs and also how to change the my.conf to use those certs.  I've also checked the DB that "use_ssl" is active...so now I need to write the code to connect.

 

Here's what I've tried:

 

$host = "localhost";  //change this to whatever your host is, usually localhost
$username = "xxx";   //change this to your mysql username
$password = "xxx"; //change this to whatever your password is
$DBName = "paypal";  //DO NOT CHANGE THIS FIELD
$port = "3306";
$socket = "/var/run/mysqld/mysqld.sock";

$mysqli = new mysqli( );

$mysqli->init( );

$mysqli->options(mysqlI_READ_DEFAULT_FILE, '/etc/mysql/my.cnf');
$mysqli->options(mysqlI_OPT_LOCAL_INFILE, false);
$mysqli->options(mysqlI_OPT_connect_TIMEOUT, 600);

$mysqli->real_connect($host,$username,$password,$DBname,$port,$socket,mysqlI_CLIENT_ssl);


$usql = "insert IGNORE into purchases values ('$pdate', '$first_name', '$last_name', '$payer_status', '$payer_email', '$payer_id', '$payment_status', '$amount', '$txn_id', '$txn_type', '$payment_type', '$custom', '$mc_fee', '$pending_reason', '$verify_sign', '$pass', '$cell', '$provider')";

 

 

and I get errors.

 

Warning: mysqli::options() expects parameter 1 to be long, string given in /var/www/web6/web/paypal.php on line 39

Which is the load my.cnf line

 

 

Warning: mysqli::options() expects parameter 1 to be long, string given in /var/www/web6/web/paypal.php on line 40

Which is the line ---$mysqli->options(mysqlI_OPT_LOCAL_INFILE, false);

 

Warning: mysqli::options() expects parameter 1 to be long, string given in /var/www/web6/web/paypal.php on line 41

Which is the line ---$mysqli->options(mysqlI_OPT_connect_TIMEOUT, 600);

 

Warning: mysqli::real_connect() expects parameter 7 to be long, string given in /var/www/web6/web/paypal.php on line 43

Which is the line ---$mysqli->real_connect($host,$username,$password,$DBname,$port,$socket,mysqlI_CLIENT_ssl);

 

and this last one...which obviously means it didn't connect right

Warning: mysql_query() [function.mysql-query]: Access denied for user 'www-data'@'localhost' (using password: NO) in /var/www/web6/web/paypal.php on line 55

 

 

Can someone point me in the right direction here?  I hate to say it, but the documentation (php side, not the mysql side) is pretty scarce on how to connect.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/120758-connect-to-a-mysql-db-over-ssl/
Share on other sites

Update...

 

no errors with this code...but no insert into the db either!  The only good thing is that I appear to be connecting to the DB with SSL!

 

$link = mysqli_connect("localhost", "xxx", "xxx", "paypal");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}


$query = "insert IGNORE into purchases values ('$pdate', '$first_name', '$last_name', '$payer_status', '$payer_email', '$payer_id', '$payment_status', '$amount', '$txn_id', '$txn_type', '$payment_type', '$custom', '$mc_fee', '$pending_reason', '$verify_sign', '$pass', '$cell', '$provider')";

mysqli_query($link, $query);

echo "<p>Thank You, you need to set your password to listen.</p><meta http-equiv=Refresh content=3;url='page.php?page=setpassword'>";



/* close connection */
mysqli_close($link);
?>

 

All of the inserts are defined properly before the code quoted above.  Thanks for any help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.