284 TIAS
PHP & MySQL
    <?php
    
      // p.248 Example 11-1 "The login.php file"
      // p.250 Example 11-2 "Connecting to a MySQL server using PDO"
    
      // NOTE: in your files, instead of "localhost" use YOUR machine name 
      //       as I've done below with 'farheen.sewanee.edu'
    
      try {
        $pdo = new PDO("mysql:host=farheen.sewanee.edu;dbname=aliens", "guest", "pssst");
      } catch (PDOException $e) {
        echo "Sorry, that didn't work out for you...";
      }
    
    ?>
                  

  • Connecting to your database thru a webpage

    What can go wrong?

    (PHP Data Object - further reading)

  • Figure 11-3

  • Figure 11-4

  • Figure 11-4COLOR

  • Figure 11-5 (plus date tias)
    fyi, I used "order by colorID desc" at the end of select for all colors.
      // playing with date functions & formats...
      // 'h'  12-hour, 'i' for minutes, 's' seconds and  A for am/pm
      $date .= date('h:i:s A'); 
    
      $query="insert into color(name,red,green,blue) values ('PINK! @$date',240,3,252)";
             

  • Figure 11-6 (all in color!!!)

  • As you continue to read...

    In this class, I will never ask you to grant to any web user privileges sufficient to create or drop tables and/or datbases so you can ignore the php involved in Examples 11-7, 11-8, & 11-9.

When in doubt...do as I say, not as I do.