Suppose, i am connect to mysql database using mysql_coni(), so that now i am try to connect IBM SQL Database which provide by IBM Bluemix.
Which function or which correct way used to connect PHP With IBM SQL Database within bluemix.
Suppose, i am connect to mysql database using mysql_coni(), so that now i am try to connect IBM SQL Database which provide by IBM Bluemix.
Which function or which correct way used to connect PHP With IBM SQL Database within bluemix.
To connect to the SQLDB service in Bluemix you can use db2_connect. You should use a connection string instead of separate database/username/pw/etc. parameters because it is a remote DB service
Following an example of parsing VCAP_SERVICES to connect to the SQLDB service in PHP:
# Decode JSON for DB connection parameters
$services_json = json_decode($json,true);
$sqldb = $services_json["sqldb"];
if (empty($sqldb)) {
echo "No sqldb service instance bound. Please bind a sqldb service instance before";
return;
}
$sqldb_config = $services_json["sqldb"][0]["credentials"];
// create DB connect string
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};";
$conn_string .= "DATABASE=" . $sqldb_config["db"] . ";";
$conn_string .= "HOSTNAME=" . $sqldb_config["host"] . ";";
$conn_string .= "PORT=" . $sqldb_config["port"] . ";";
$conn_string .= "PROTOCOL=TCPIP;";
$conn_string .= "UID=" . $sqldb_config["username"] . ";";
$conn_string .= "PWD=" . $sqldb_config["password"] . ";";
// connect to database
$conn = db2_connect($conn_string, '', '');
Please see the accepted answer in this post : https://developer.ibm.com/answers/questions/20036/how-to-compile-php-with-db2-support-in-bluemix/