ICT_10 класс_Linking a web page to a database. lesson 2

  • docx
  • 09.05.2020
Публикация на сайте для учителей

Публикация педагогических разработок

Бесплатное участие. Свидетельство автора сразу.
Мгновенные 10 документов в портфолио.

Иконка файла материала ICT_10 класс_Linking a web page to a database. lesson 2.docx

 

Long-term plan unit: 10.4А Information system

School:

Date:

Teacher name:

Grade:

Number present:

absent:

The theme of the lesson

Linking a web page to a database

Learning objectives that are achieved at this lesson (Subject Programme reference)

10.3.3.2 link a web page to a database

Lesson objectives

Learn how to link a web page to a database

Success criteria

1.      identify the necessary software to create a database site

2.      explain the scheme of the site with databases

3.      to create a database in PhpMyAdmin

4.      connect to database

5.      create queries in database

Language objectives

Students will be able to explain the scheme of the site with databases and explain parts of the program code

 

Subject-specific vocabulary & terminology:

Php script, hosting, PhpMyAdmin, open connection, close connection.

Useful sets of phrases for dialogue and writing: :

To create a site with a database, you need the following software:.....

The code for connecting to the database contains the following commands…

Values instilled at the lesson

 Respect for each other, cooperation.

Cross-curricular links

 Different subject areas depending on the student's chosen topic

Previous learning

 

Students have web page creation skills and database creation skills.

Course of the lesson

Planned stages of the lesson

Planned activities at the lesson

Resources

Beginning

3 min

Work in pairs. Sheet of mutual evaluation of the work from the last lesson, with the help of signs +/-:

name of student

Table

The web page

 

lessons

 

 

Courses

 

Teachers

 

 

2 min

Connection to the database via php takes place in 4 stages:

* Open connection to server

•          Select database

* * Send query to database

* Database close (not always)

Consider the examples of each stage separately

 

5  min

Connecting to the server via php

1.      1. Create a variable associated with a connection to a mySql server:

1
2
3
4
5
<?php
$conn = mysql_connect ("localhost", "root", "");
mysql_close($conn);
?>

Php function mysql_connect-opens a connection to a MySQL server. Three parameters of the function:

1.            "localhost" - server, when working locally, the value "localhost" is specified»

2.            "root" — the user name, when working locally is usually specified " root»

3.            ""- the third parameter is password, no password locally

 

2. Handling possible errors

1

2

3

4

5

6

7

<?php

$conn = mysql_connect ("localhost", "root", "")

        or die("Нет соединения: " . mysql_error());

print ("Удачно соединено");

mysql_close($conn);

or die (mysql_error())

The php mysql_error () function returns the error string of the last MySQL operation and can be used not only when trying to connect to the server, but also in other variants of working with the mysql database

http://labs-org.ru/mysql-2/

5 min

Selecting a mySQL database and connecting to it

<?php

$conn = mysql_connect ("localhost", "root", "")

        or die("Нет соединения: " . mysql_error());

print ("Удачно соединено");

mysql_select_db("db_name", $conn);
?>

Php function mysql_connect-selects MySQL database. Two function parameters:

• "db_name" is the name of the database

• $conn — a pointer to the connection

Presentation to the lesson

5 min

Create a database query

<?php

$conn = mysql_connect ("localhost", "root", "")

        or die("Нет соединения: " . mysql_error());

print ("Удачно соединено");

mysql_select_db("db_name", $conn);

 

$sql="SELECT * FROM  `teachers` WHERE  `name`='Иванов'" ;

$sql= (string) $sql;

$result = mysql_query($sql, $conn)

or die ("no!".mysql_error());

?>

Php mysql_query function-sends a request to the active database of the server referenced by the passed pointer. Two function parameters:

• $sql query

• $conn — a pointer to the connection

Important: to find the error easier, you can print a query:

 

echo $sql;

Presentation to the lesson

5 min

Processing of query results to mySQL database
<?php
mysql_select_db("db_name", $conn);
$sql="SELECT * FROM  `teachers` WHERE  `name`='Иванов'" ;
$sql= (string) $sql;
$result = mysql_query($sql, $conn)
or die ("no!".mysql_error());
while($row = mysql_fetch_array($result)) {
        $name=$row["name"];
        $zp= $row["zarplata"];
        echo $name.' '. $zp;
}
?>

 

Php function mysql_fetch_array-returns an array with the processed query result series or FALSE if there are no rows that meet the query parameters

Presentation to the lesson

Additionally

 

SOLVING PROBLEMS WITH ENCODING

Important: in some cases, if the results are not displayed, you should change the encoding to windows 12-51

12
3
4
5
$conn = mysql_connect ("localhost", "root", "")
        or die("Нет соединения: " . mysql_error());
print ("Удачно соединено");
mysql_select_db("institute", $conn);
mysql_query("SET NAMES cp1251");

 

USE FOR FOREACH LOOP PROCESSING FOREACH

1
2
3
4
foreach($result as $row){
        $name=$row["name"];
        $zp= $row["zarplata"];
        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Additionally

 

 

Example: print all entries for the surname Ivanov

1

2

3

4

5

6

7

8

9

10

11

$conn = mysql_connect ("localhost", "root", "")

         or die("Нет соединения: " . mysql_error());

print ("Удачно соединено");

mysql_select_db("institute", $conn);

$sql="SELECT * FROM  `teachers` WHERE  `name`='Иванов'" ;

$sql= (string) $sql;

$result = mysql_query($sql, $conn)

         or die ("no!".mysql_error());

// сохраняем результат в виде массива $row

$row=mysql_fetch_array($result);

print_r($row);

http://labs-org.ru/wp-content/uploads/2016/10/1-7.png

The print_r() function in php is used to output human-readable information about a variable

Important: absolutely the same result will be an appeal to the field by its name and by its number:

echo $row["name"];

and  echo $row[1];

 

A loop is used to display all values:

while($row=mysql_fetch_assoc($result)){

  echo $row["name"]."<br>";

}

POINT SAMPLING (SINGLE RECORD)

Syntax: mysql_result($result, int row, string field)

Example: Select the value of the field "name" in the record number 1

mysql_result($result, 1, "name")

 

5 min

Task: run a query to select id and name from the teacher table.

Display the data on the page as: id: name

http://labs-org.ru/mysql-2/

3 min

Mutual evaluation of the result of the task using a 10-point scale.

Картинки по запросу 10 балльная шкала оценивания

 

2 min

 

Reflection

https://ds02.infourok.ru/uploads/ex/0fa0/000441d7-8da1a3ac/img14.jpg

 

Differentiation – how do you plan to give more support? How do you plan to challenge the more able learners?

Assessment – how are you planning to check students’ learning?

Health and safety regulations

Differentiation can be by task, by outcome, by individual support, by selection of teaching materials and resources taking into account individual abilities of learners (Theory of Multiple Intelligences by Gardner).

Differentiation can be used at any stage of the lesson keeping time management in mind.

 

Use this section to record the methods you will use to assess what students have learned during the lesson.

Health promoting techniques

Breaks and physical activities used.

Points from Safety rules used at this lesson.

Reflection

Were the lesson objectives/learning objectives realistic? Did all learners achieve the LO?

If not, why?

Did my planned differentiation work well?

Did I stick to timings?

What changes did I make from my plan and why?

 

Use the space below to reflect on your lesson. Answer the most relevant questions from the box on the left about your lesson. 

 

Summary evaluation

 

 

What two things went really well (consider both teaching and learning)?

1:

 

2:

What two things would have improved the lesson (consider both teaching and learning)?

1:

 

2:

What have I learned from this lesson about the class or achievements/difficulties of individuals that will inform my next lesson?

 

 

 


 

Скачано с www.znanio.ru