Erasmus Exchange in Ionian University

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
Intermediate PHP & MySQL
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
PHP-MySQL By Jonathan Foss. PHP and MySQL Server Web Browser Apache PHP file PHP MySQL Client Recall the PHP architecture PHP can communicate with a MySQL.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
Create an online booking system (login/registration)
PHP – MySQL Extensions. Table used in most examples CREATE TABLE product ( rowID INT NOT NULL AUTO_INCREMENT, productid VARCHAR(8) NOT NULL, name VARCHAR(25)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
PHP Database Processing CIS 1715 Web Technologies.
Storing and Retrieving Data
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
CSC 2720 Building Web Applications Accessing MySQL from PHP.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 8 – Review Reference:
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in PHP consists of a number of functions.
Web Systems & Technologies
Tried my best to simplify it for you!
PHP (Session 2) INFO 257 Supplement.
ASP.NET Programming with C# and SQL Server First Edition
Remote hosts and web servers
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
Session 4 PHP & MySQL.
Web Design and Development
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
PHP and MySQL.
PHP-language, database-programming
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
MySQL Web Application Connecting to a MySQL database
Software Engineering for Internet Applications
Web Programming Language
PHP: Database Basic Selection FdSc Module 109
PHP: Database connection
Tutorial 6 PHP & MySQL Li Xu
Web Programming– UFCFB Lecture
MySQL Web Application Connecting to a MySQL database
PHP AND MYSQL.
PHP Forms and Databases.
Database Access with PHP and MySQL
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

Erasmus Exchange in Ionian University 30 april – 3 May 2018

Internet Technologies MySQL connect to the Apache web server via PHP Internet Technologies MySQL connect to the Apache web server via PHP. Application: Registration on Site Doru Anastasiu Popescu, associate professor, PhD Faculty of Sciences, Physical Education and Informatics Department of Mathematics and Informatics

MySQL Connection Using PHP Script PHP + MySQL Database System PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform) PHP 5 and later can work with a MySQL database using: MySQLi extension (the "i" stands for improved) PDO (PHP Data Objects) Earlier versions of PHP used the MySQL extension. PHP provides various functions to access the MySQL database and to manipulate the data records inside the MySQL database. You would require to call the PHP functions in the same way you call any other PHP function. The PHP functions for use with MySQL have the following general format: mysql_function(value,value,...); The second part of the function name is specific to the function, usually a word that describes what the function does.

mysql_connect()  PHP provides mysql_connect() function to open a database connection. This function takes five parameters and returns a MySQL link identifier on success or FALSE on failure. Parameter & Description: server Optional − The host name running the database server. If not specified, then the default value will be localhost user Optional − The username accessing the database. If not specified, then the default will be the name of the user that owns the server process. passwd Optional − The password of the user accessing the database. If not specified, then the default will be an empty password new_link Optional − If a second call is made to mysql_connect() with the same arguments, no new connection will be established; instead, the identifier of the already opened connection will be returned.

mysql_connect() and mysql_close() client_flags Optional − A combination of the following constants: MYSQL_CLIENT_SSL − Use SSL encryption. MYSQL_CLIENT_COMPRESS − Use compression protocol. MYSQL_CLIENT_IGNORE_SPACE − Allow space after function names. MYSQL_CLIENT_INTERACTIVE − Allow interactive timeout seconds of inactivity before closing the connection. Example $msql=mysql_connect("localhost","root",""); You can disconnect from the MySQL database anytime using another PHP function mysql_close(). This function takes a single parameter, which is a connection returned by the mysql_connect() function.

mysql_select_db() The mysql_select_db() function sets the active MySQL database. This function returns TRUE on success, or FALSE on failure. Syntax mysql_select_db(database,connection) Parameter database - Required. Specifies the database to select. connection - Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() is used. Example $baza=mysql_select_db("enrolled");

mysql_errno() The mysql_errno() function returns the error number of the last MySQL operation. This function returns 0 (zero) if no error has occurred. Syntax mysql_errno(connection) Parameter connection - Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() is used.

mysql_error() The mysql_error() function returns the error description of the last MySQL operation. This function returns an empty string ("") if no error occurs. Syntax mysql_error(connection) Parameter Connection - Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() is used. Example $result=mysql_query($interrogation); if(!$result) echo mysql_errno().":".mysql_error(); else echo "The table was created!";

mysql_query() The mysql_query() function executes a query on a MySQL database. This function returns the query handle for SELECT queries, TRUE/FALSE for other queries, or FALSE on failure. Syntax mysql_query(query,connection) Parameter query - Required. Specifies the SQL query to send. connection - Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() is used. Example $interrogation="create table logindata(name char(30) primary key, password char(10))"; $result=mysql_query($interrogation); if(!$result) echo mysql_errno().":".mysql_error(); else echo "The table was created!";

mysql_fetch_array() The mysql_fetch_array() function returns a row as an associative array and/or a numeric array. This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows. Syntax mysql_fetch_array(data,array_type) Parameter data - Required. Specifies which data pointer to use. The data pointer is the result from the mysql_query() function array_type - Optional. Specifies what kind of array to return. Possible values: MYSQL_ASSOC - Associative array MYSQL_NUM - Numeric array MYSQL_BOTH - Default. Both associative and numeric array

mysql_fetch_array() Note: After the data is retrieved, this function moves to the next row. Each subsequent call to mysql_fetch_array() returns the next row. Tip: Field names returned by this function are case-sensitive. Example while ($row = mysql_fetch_array($result))      echo $row[0].“ “. $row[1].”<BR/>”;  

require_once() require_once() statement can be used to include a php file in another one, when you may need to include the called file more than once. If it is found that the file has already been included, calling script is going to ignore further inclusions. If a.php is a php script calling b.php with require_once() statement, and does not find b.php, a.php stops executes causing a fatal error. Syntax: require_once('name of the called file with path');

Diagram for Application Registration on Site

Files of web application btab.php - script for creating the enrolled database and the logindata table from it. The login data table contains the following fields: name and password The btab.php script will be launched in executions once, at the beginning of the application’s usage. main.php –is used for selecting from 2 choices one: the login or registration on the web site. For the registration on the web site the following script is launched in execution: singup.php, and for the login identification.php. singup.php –allows the insertion of the data for registration. These data are took over by the script: enroll.php enroll.php – cheks if the data already exists in the table and if the password is introduced correct. If so the data is introduced in the table. identification.php –takes over the data for the registration. The took over data is checked using the verif.php script. verif.php –is used to check if the took over data are in the table and if so the registration is realised and the access to the secure page is given.

1. Creating the database and the table btab.php <?php $msql=mysql_connect("localhost","root",""); if(!$msql){ echo "No connection to MySQL was made"; exit; } $result=mysql_query("CREATE DATABASE enrolled"); if(!$result){ echo "Failed to create the database!"; else echo "The database was created! <BR/>";

1. Creating the database and the table continuation $baza=mysql_select_db("enrolled"); $interrogation="create table logindata(name char(30) primary key, password char(10))"; $result=mysql_query($interrogation); if(!$result) echo mysql_errno().":".mysql_error(); else echo "The table was created!"; ?>

2. Start web application main.php <html> <body> <h2> Welcome to the site ...</h2> <a href="http://localhost:8888/identification.php"> Identification</a> <br><br> <a href="http://localhost:8888/singup.php"> Sign up </a> </body> </html>

3. Sending data to the server singup.php <html> <body> <form action="enroll.php" method="post"> Name<br> <input name="name" type="text"><br> Password<br> <input name="password1" type="password"><br> Password again<br> <input name="password2" type="password"><br> <input type="submit", value="Sign up!"> </form> </body> </html>

4. Entering data into table logindata from database enrolled enroll.php <?php $msql=mysql_connect("localhost","root",""); if(!$msql){ echo "No connection to MySQL was made"; exit; } $db=mysql_select_db("enrolled"); if(!$db){ echo mysql_errno().":".mysql_error(); $name=$_POST['name']; if(strcmp($name,"")==0){ echo "You have not written name"; require_once("singup.php");

4. Entering data into table logindata from database enrolled continuation $password1=$_POST['password1']; $password2=$_POST['password2']; if(strcmp($password1,$password2)!=0){ echo "incorrect password"; require_once("singup.php"); exit; } $request="insert into logindata (name,password) values ('$name','$password1')"; $res=mysql_query($request); if(!$res){ echo "Name that exists in the database!"; }else echo "OK! You have been entered in our database."; ?>

5. Sending data to the server for verification identification.php <html> <body> <form action="verif.php" method="post"> Name<br> <input name="name" type="text"><br> Password<br> <input name="password" type="password"><br> <input type="submit" value="Sign me!"> </form> </body> </html>

6. Verification data verif.php <?php $msql=mysql_connect("localhost","root",""); if(!$msql){ echo "It could not make a connection to MySQL!"; exit; } $bd=mysql_select_db("enrolled"); if(!$bd){ echo mysql_errno().":".mysql_error();

6. Verification data continuation $name=$_POST['name']; $password=$_POST['password']; $request="select name from logindata where name='$name' and password='$password'"; $result=mysql_query($request); $row=mysql_fetch_array($result); if($row["name"]!=$name){ echo "Your name and/or password are incorrect"; require_once("identification.php"); }else{ echo "Welcome ".$row["name"]."! <br/>"; require_once("result.php"); } ?>

7. The web page for which login was made result.php <html> <body> <h1> This is the restricted web page! </body> </html>

Laboratory task PHP-MySQL Check the presented application Develop a web application for presenting the student’s timetable from a faculty. For registration the required data will be: email, name, year of study, specialty. When the registration on site will be realised a web page with the suitable timetable will open with the suitable year of study and specialty. The application will contain a script for creating a table with the information about the timetable.

Bibliography PHP-MySQL https://www.w3schools.com/php/ https://www.tutorialspoint.com

WEB SITE: http://www.dopopan.ro Thank you! Questions Email: dopopan@yahoo.com WEB SITE: http://www.dopopan.ro