Oracle by Example brandingConnect a PHP Application to MySQL

part 0Before You Begin

This 10-minute tutorial you how to deploy a PHP application to Oracle Application Container Cloud Service and how to integrate Oracle MySQL Service with your application.

Background

Oracle Application Container Cloud Service provides a lightweight infrastructure so that you can run Java, PHP, and Node.js applications in Oracle Cloud. To develop more robust applications, you can integrate this cloud service with other Oracle services (for example, Oracle MySQL Cloud Service).


part 1Deploy Your Application to Oracle Application Container Cloud Service

  1. Log in to Oracle Cloud at http://cloud.oracle.com/. Enter your account credentials in the Identity Domain, User Name, and Password fields.
  2. To open the Oracle Application Container Cloud Service console, click Instances in the dashboard.
    Instance of Oracle Application Container Cloud Service
    Description of the illustration open_console.png
  3. In the Applications list view, click Create Application.
  4. In the Create Application dialog box, click PHP.
  5. In the Application section, enter EmployeeService for the name of your application and click Browse.
  6. In the File Upload dialog box, select the employee-service.zip file located in the target directory, and click Open.
  7. Keep the default values in the Instances and Memory fields and click Create.

part 2Add the MySQLCS Service Binding

  1. Wait until the application is created and click the application name.
  2. Click the Deployments tab. In the Service Binding section, click Add.
  3. In the Service Type field, select MySQLCS Service. Enter or select values in the Service Name, Username, and Password fields, and click Save.
  4. In the Deployments dialog box, click Apply Edits.
  5. Wait until the application is restarted.

part 3Test the Application

  1. In the Oracle Application Container Cloud Service console, click the URL of your application.
  2. Click Setup the database.
    Index page of the employee service application
    Description of the illustration index-page.png

    The EMPLOYEE table is created in the database, and it has five employee records.

    Setup database output
    Description of the illustration setup_database.png
  3. Open a command-line window (or terminal in Linux).
  4. Query all employee entities.
    curl app_endpoint/employees-rest-api.php/employees
  5. Create an employee record and replace the app_endpoint placeholder with the URL of your application.
    curl -i -X POST -H "Content-Type:application/json" -d "{ \"firstName\" : \"John\",  \"lastName\" : \"Smith\",\"birthDate\":\"1957-10-14\", \"phone\":\"193-754-4112\",\"email\":\"john.smith@example.com\",\"title\" : \"Manager\",\"dept\" : \"Sales\" }" app_endpoint/employees-rest-api.php/employees

    Because five records were already inserted in the table, the ID of the new record is 6.

  6. Get the employee by ID.
    curl app_endpoint/employees-rest-api.php/employees/6 
  7. Update the employee.
    curl -i -X PUT -H "Content-Type:application/json" -d "{ \"firstName\" : \"John\",  \"lastName\" : \"Smith\",\"birthDate\":\"1957-12-08\", \"phone\":\"193-124-8212\",\"email\":\"john.smith@example.com\",\"title\" : \"Manager\",\"dept\" : \"IT\" }" app_endpoint/employees-rest-api.php/employees/6
  8. Delete the employee.
    curl -i -X DELETE app_endpoint/employees-rest-api.php/employees/6

more informationWant to Learn More?