實機操作練習題

  1. 登入
    1. 遠端登入 kvm6 虛擬機。
    2. 以 root 身份登入 mysql。
  2. 新增資料庫、資料表。
    1. 建立資料庫 dbq。
    2. 在資料庫 dbq 中建立資料表 tblq,包含下列欄位:
      1. id int not null auto_increment,
      2. subject varchar(100) not null,
      3. author varchar(40) not null,
      4. score tinyint,
      5. primary key (id)
    3. 在資料表 tblq,依序加入五筆資料。
      subject perl, author abc321, score 79
      subject ruby, author abc234, score 65
      id 10, subject PHP, author abc124, score 90
      id 11, subject python, author abc222, score 45
      subject ruby, author abc222, score 85
      
  3. php 程式一
    1. 使用以下 php 範例程式,其中 ........ 依要求填入 mysql 語法,其中資料庫名稱依題目要求修改。
      <?php
      $dbhost = 'localhost:3306';
      $dbuser = 'root';
      $dbpass = '123qwe';
      $author = $_GET['author'];
      $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error().PHP_EOL);
      $sql = ".............";
      $retval = mysql_db_query( 'dbd',$sql ) or die(mysql_error().PHP_EOL);
      mysql_close($conn);
      ?>
      
    2. tblq1.php:在資料表 tblq 中新增一筆資料,author 以變數由 php get 取得內容,id 自動產生,其他欄位自行決定內容。
    3. tblq2.php:刪除資料表 tblq 中 author=$author 的資料,變數 $author 由 php get 取得。
  4. 使用 GET 變數$_GET['author'] 由網址加問號取得內容,如以下範例變數 author=dywang。
    http://kvm6.deyu.wang/tblq1.php?author='dywang'
    
  5. php 程式二
    1. 使用以下 php 範例程式,其中 ........ 依要求填入 mysql 語法,其中資料庫名稱依題目要求修改。
      <?php
      $dbhost = 'localhost:3306';
      $dbuser = 'root';
      $dbpass = '123qwe';
      $str = $_GET['str'];
      $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error().PHP_EOL);
      $sql = ".............";
      $retval = mysql_db_query( 'dbd',$sql ) or die(mysql_error().PHP_EOL);
      while($row = mysql_fetch_array($retval, MYSQL_NUM)) {
      	echo "{$row[0]}\t{$row[1]}\t{$row[2]}\t{$row[3]}\n";
      }
      mysql_close($conn);
      ?>
      
    2. tblq3.php:從資料表 tblq 中找出所有欄位資料並以 $str 排序,變數 $str = $_GET('str') 由 php get 決定,查詢以符號 ';' 結束。
    3. tblq4.php:從資料表 tblq 中找出 author 後面幾個字元為 $str 的所有欄位資料,變數 $str = $_GET('str') 由 php get 決定,查詢以符號 ';' 結束。
    4. tblq5.php:更新資料表 tblq 中 author 後面幾個字元為 $str 的紀錄,其欄位 subject 欄位資料都更新 linux,變數 $str = $_GET('str') 由 php get 決定。