Week 10 - Connecting to PostGreSQL on the opentech Server.

In order for your opentech version of your websites to connect to a database, the database must be accessible from the opentech server. Your local computer is NOT accessible as necessary.

Preparation

SQL Script Location

  1. Open your regular folder in VSCode, and create a new folder called sql in the root folder. (beside the week or lab folders)
  2. Upload the SQL file(s) provided to this folder. You will place all future SQL scripts in this folder as well.
  3. Connect to the opentech server through FTP (fileZilla or WinSCP) and upload the sql folder to the opentech server.

Executing Scripts on the Opentech Server

In order to execute SQL creation scripts on the opentech server, you will need to connect to opentech through Putty. Tutorial on Putty in Week 1 notes.

  1. Connect to your opentech space via putty and navigate to the sql folder using
    cd /var/www/html/inft1206/username/sql

    replacing username with your opentech username. Some of the basic Putty commands are found here.
  2. Run the creation script using the following command:
    psql -d username_db -f lab7_bond_movies.sql
  3. You should received output that looks something like:
    DROP TABLE
    DROP TABLE
    CREATE TABLE
    ALTER TABLE
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    INSERT 0 1
    CREATE TABLE
    ALTER TABLE
    INSERT 0 1
    INSERT 0 1...

Executing Sample PHP Connection

  1. Download the sample php file provided: sample file
  2. Create a folder called week10 in VSCode and save the file in this folder.
  3. Modify the file to change the $conn variable value to:
    $conn = pg_connect("host=127.0.0.1 dbname=YOUR_DB_NAME user=YOUR_USER_ID password=YOUR_DB_PASSWORD" );
    
    replacing the relevant parts with your information.
  4. Upload the week10 folder to the opentech server and then in a browser, browse to: https://opentech.durhamcollege.org/inft1206/username/week10/lab7_bond_info.php
    Note: that Serving PHP will not work this week, we will finish these setups next week!