Hi,

I currently using below to connect to MySQL from PHP.

How can I use the same or anyother way to connect to MongoDB from PHP?

<?php
header("Content-Type: application/json");

if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

$customer_id = $_GET["customer_id"];

$mysql_host = "mysql:host=mysql.my_domain.com;dbname=my_db";
$mysql_user = "my_user";
$mysql_password = "my_password";
$mysql_options = array
(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);

// $mysql_connection;
$mysql_connection = new PDO($mysql_host, $mysql_user, $mysql_password, $mysql_options);
$mysql_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$mysql_query = $mysql_connection->prepare('CALL sp_populate_customer_addresses(aram_customer)');
$mysql_query->bindParam('aram_customer', $customer_id, PDO::PARAM_STR);
$mysql_query->execute();

if ($mysql_query->rowCount() <= 0) { echo "false"; }
else
{
$jsonData = array();

while($mysql_row = $mysql_query->fetch())
{
$jsonData[] = $mysql_row;
}

echo json_encode($jsonData);
}
?>



Thanks,
Jassim