ICT_10 класс_Linking a web page to a database. lesson 2
Оценка 4.6

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

Оценка 4.6
pptx
09.05.2020
ICT_10 класс_Linking a web page to a database. lesson 2
ICT_10 класс_Linking a web page to a database. lesson 2.pptx

Linking a web page to a database

Linking a web page to a database

Linking a web page to a database

Learning objective :

link a web page to a database

The theme of the lesson :

Mutual evaluation of the practical task 1

Mutual evaluation of the practical task 1

Mutual evaluation of the practical task

1. In PhpMyAdmin, create a database named Institute.
2. Fill in the tables with the data for the teachers, courses, and lessons table
3. Link the tables together through the values of the id and tid records.

name of student

Table

The web page

lessons

Courses

Teachers

To open a connection to the server

To open a connection to the server

To open a connection to the server
Select database
Send query to database
Closing database (not always)

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

Connecting to the server via php

Connecting to the server via php

Connecting to the server via php


Php function mysql_connect-opens a connection to a MySQL server.
Three parameters of the function:
"localhost" - server, when working locally, the value "localhost" is specified»
"root" — the user name, when working locally is usually specified " root»
""- the third parameter is password, no password locally

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

Connecting to the server via php 2

Connecting to the server via php 2

Connecting to the server via php

2. Handling possible errors

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

Selecting a mySQL database and connecting to it

Selecting a mySQL database and connecting to it

Selecting a mySQL database and connecting to it

Php function mysql_connect-selects MySQL database. Two function parameters:
"db_name" — database name
$conn — a pointer to the connection

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

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

a pointer to the connection

echo $sql;

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

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

Processing of query results to mySQL database

Processing of query results to mySQL database

Processing of query results to mySQL database

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

Example: print all entries for the surname

Example: print all entries for the surname

Example: print all entries for the surname Ivanov

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"];

И echo $row[1];

Task: Run the query to fetch id and name from the teacher table

Task: Run the query to fetch id and name from the teacher table

Task:  
Run the query to fetch id and name from the teacher table.
Display the data on the web page as: id: name

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

mysql_result($result, 1, "name")

assessment verbal feature expression in points unsatisfactorily 1 almost satisfactory 2 satisfactorily 3 highly satisfactory 4 almost good 5 good 6 quite well 7 almost…

assessment verbal feature expression in points unsatisfactorily 1 almost satisfactory 2 satisfactorily 3 highly satisfactory 4 almost good 5 good 6 quite well 7 almost…

assessment

verbal feature

expression in points

unsatisfactorily

1

almost satisfactory

2

satisfactorily

3

highly satisfactory

4

almost good

5

good

6

quite well

7

almost perfect

8

perfectly

9

superbly

10

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

ICT_10 класс_Linking a web page to a database. lesson 2
Скачать файл