Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Employee{
- public $EmployeeNumber;
- public $LastName;
- public $FirstName;
- public $extension;
- public $cityOffice;
- public $jobTittle;
- public $creditLimit;
- public $customers;
- }
- class payments{
- public $paymentDate;
- public $amount;
- public $checkNumber;
- }
- class Customer{
- public $customerNumber;
- public $CustomerName;
- public $contactLastName;
- public $contactFirstName;
- public $city;
- public $country;
- public $payment;
- }
- $db_host="localhost"; $db_nom="practicaBdd"; $db_user="root"; $db_pass="";
- $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_nom) ;
- $result = mysqli_query($conn, "SELECT * FROM orderdetails ");
- try {
- $manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
- while ($row = mysqli_fetch_array($result)) {
- $e = new Employee();
- $e->EmployeeNumber = $row["EmployeeNumber"];
- $e->LastName = $row["LastName"];
- $e->FirstName = $row["FirstName"];
- $e->extension = $row["extension"];
- $e->cityOffice = $row["cityOffice"];
- $e->jobTittle = $row["jobTittle"];
- $e->creditLimit = $row["creditLimit"];
- $e->customers = array()
- $result_customer = mysqli_query($conn, "SELECT * FROM orderdetails ");
- while ($row1 = mysqli_fetch_array($result_customer){
- $i = new Customer();
- $i->customerNumber = row1["customerNumber"];
- $i->CustomerName = row1["CustomerName"];
- $i->contactLastName = row1["contactLastName"];
- $i->contactFirstName = row1["contactFirstName"];
- $i->city = row1["city"];
- $i->country = row1["country"];
- $i->payment = array();
- $result_payments = mysqli_query($conn, "SELECT * FROM orderdetails ");
- while ($row2 = mysqli_fetch_array($result_payments){
- $o = new payments();
- $o->paymentDate = row2["paymentDate"];
- $o->amount = row2["amount"];
- $o->checkNumber = row2["checkNumber"];
- array_push($i->payment, $o);
- }
- mysqli_free_result($result_payments);
- array_push($e->customers, $i);
- }
- mysqli_free_result($result_customer);
- $bulk = new MongoDB\Driver\BulkWrite;
- $bulk->insert($e);
- $res = $manager->executeBulkWrite('test.orders', $bulk);
- }
- mysqli_free_result($result);
- mysqli_close($conn);
- }catch(Exception $e) {
- echo "EXCEPTION: ".$e->getMessage(), "\n";
- exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement