PHP: MySQL. PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data.

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
Web Database Programming Connecting Database to Web.
Nic Shulver, Introduction to SQL Topics covered Structured Query Language What can it do? Advantages of SQL Why bother with SQL?
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.
Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
INTERNET APPLICATION DEVELOPMENT For More visit:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
PHP MySQL Introduction
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
PHP Part 2.
Chapter 9 Using PHP with MySQL. header.html Script 9.1 on page 266 des/header.html
Technology & Management Club Development Software Overview.
PHP with MySQL 1.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Web Programming Language Week 7 Dr. Ken Cosh PHP and storage.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Creating A Database Driven Website 1.Setting Up Your Web Server 2.Creating a Database 3.Creating a Webpage to Display Information From a Database 4.Creating.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
PHP Database Pemrograman Internet. PHP MySQL Database With PHP, you can connect to and manipulate databases. MySQL is the most popular database system.
CHAPTER 10 PHP MySQL Database
CSC 2720 Building Web Applications Accessing MySQL from PHP.
MySQL MySQL and PHP – interacting with a database.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
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.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
PHP & MY SQL Instructor: Monireh H. Sayadnavard 1.
Web Systems & Technologies
PHP Built-In Functions
PHP: MySQL Lecture 14 Kanida Sinmai
IS1500: Introduction to Web Development
Web Design and Development
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Chapter 9 Using PHP with MySQL.
Introduction to Web programming
Unit 2 MY SQL DATABASE PROGRAMMING
PHP + MySQL Commands Refresher.
PhpMyaAmin & MySQL PHP: Hypertext Preprocessor.
Ch. 3. PHP (이 강의 내용의 대부분 예들은 w3schools. com/php/default
ISC440: Web Programming 2 Server-side Scripting PHP 3
Introduction to Web programming
MySQL Web Application Connecting to a MySQL database
CIS 388 Internet Programming
PHP Hüseyin GÜNEŞ, 2018.
SQL Queries Chapter No 3.
Web Programming Language
Tutorial 6 PHP & MySQL Li Xu
MySQL Web Application Connecting to a MySQL database
Introduction to Web programming
Conection
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:

PHP: MySQL

PHP Connect to MySQL 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. However, this extension was deprecated in 2012.

Example <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = mysqli_connect($servername, $username, $password); // Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); } echo "Connected successfully"; ?>

Create a database

Create a table

Close the Connection mysqli_close($conn);

PHP Insert Data Into MySQL <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); } $sql = "INSERT INTO MyGuests (firstname, lastname, ) VALUES ('John', 'Doe', if (mysqli_query($conn, $sql)) { echo "New record created successfully"; } else { echo "Error: ". $sql. " ". mysqli_error($conn); } mysqli_close($conn); ?>

PHP Get ID of Last Inserted Record <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); } $sql = "INSERT INTO MyGuests (firstname, lastname, ) VALUES ('John', 'Doe', if (mysqli_query($conn, $sql)) { $last_id = mysqli_insert_id($conn); echo "New record created successfully. Last inserted ID is: ". $last_id; } else { echo "Error: ". $sql. " ". mysqli_error($conn); } mysqli_close($conn); ?>

PHP Select Data From MySQL SELECT column_name(s) FROM table_name or we can use the * character to select ALL columns from a table: SELECT * FROM table_name

<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); } $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "id: ". $row["id"]. " - Name: ". $row["firstname"]. " ". $row["lastname"]. " "; } } else { echo "0 results"; } mysqli_close($conn); ?>

PHP Delete Data From MySQL DELETE FROM table_name WHERE some_column = some_value

<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); } // sql to delete a record $sql = "DELETE FROM MyGuests WHERE id=3"; if (mysqli_query($conn, $sql)) { echo "Record deleted successfully"; } else { echo "Error deleting record: ". mysqli_error($conn); } mysqli_close($conn); ?>

PHP Update Data in MySQL UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value

<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: ". mysqli_connect_error()); } $sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2"; if (mysqli_query($conn, $sql)) { echo "Record updated successfully"; } else { echo "Error updating record: ". mysqli_error($conn); } mysqli_close($conn); ?>

PHP Limit Data Selections From MySQL $sql = "SELECT * FROM Orders LIMIT 30"; $sql = "SELECT * FROM Orders LIMIT 10 OFFSET 15";

แบบฝึกหัด สร้างฐานข้อมูล 1 ฐานข้อมูล (myDB) สร้างตาราง 1 ตาราง (user) ประกอบด้วย Field ที่ จำเป็นเช่น username, password, วันที่สมัคร สมาชิก, ประเภทของสมาชิก, ….. สร้างฟอร์มรับข้อมูลดังกล่าว บันทักข้อมูลลงฐานข้อมูลโดยใช้ php script แสดงข้อมูลผู้ใช้ทั้งหมด ผู้ใช้สามารถเปลี่ยนรหัสผ่านได้