What is MySQLi? Since the mid-90s, Mysql extension has served as the major bridge between PHP and MySQL. Although it has performed its duty quite well,

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
PHP 5 + MySQL 5 A Perfect 10. Adam Trachtenberg PHP 5 + MySQL 5 = A Perfect mysqli extension i is for improved! All new MySQL extension for PHP.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
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 relational database management system (A relational database stores data in separate tables rather than putting all the data.
Check That Input Preventing SQL Injection Attacks By Andrew Morton For CS 410.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
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,
LIS651 lecture 7 PHP mySQL Thomas Krichel
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
PHP Data Objects Layer (PDO) Ilia Alshanetsky. What is PDO Common interface to any number of database systems. Common interface to any number of database.
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
Nic Shulver, Retrieving Stored Data Introduction This set of slides shows: The information source database structure The data.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 19: Database Support.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Codeigniter is an open source web application. It occupies a very small amount of space in the memory and is most useful for developers who aim to develop.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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.
Lecture 10 – MYSQL and PHP (Part 2)
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Database APIs and Wrappers
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.
PHP PDO & PHP SOAP Introduce. Agenda What is PHP PDO and PHP SOAP? Setup PHP PDO to connect database, query database and close the connection. Setup SOAP.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Introduction to PHP Advanced Database System Lab no.1.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
Web Programming Language Week 7 Dr. Ken Cosh PHP and storage.
Lecture 7 Maintaining State (cookies & sessions) & MySQL Interaction (revisited)
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.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
CHAPTER 10 PHP MySQL Database
CSC 2720 Building Web Applications Accessing MySQL from PHP.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
DATABASES.
PDOStatement Named Placeholders CIT336 - Connor Wiseman cit336.saveandquit.net/presentation.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
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.
Web Systems & Technologies
Web Database Programming Using PHP
PHP Built-In Functions
DEPTT. OF COMP. SC & APPLICATIONS
Introduction to Dynamic Web Programming
Web Technologies IT230 Dr Mohamed Habib.
Web Database Programming Using PHP
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Multitier Architecture, MySQL & PHP
PHP / MySQL Introduction
ISC440: Web Programming 2 Server-side Scripting PHP 3
MySQL Web Application Connecting to a MySQL database
Tutorial 6 PHP & MySQL Li Xu
MATERI PL/SQL Procedures Functions Packages Database Triggers
MySQL Web Application Connecting to a MySQL database
PHP Forms and Databases.
Introduction to Web programming
SQL Injection Attack.
Presentation transcript:

What is MySQLi? Since the mid-90s, Mysql extension has served as the major bridge between PHP and MySQL. Although it has performed its duty quite well, situation has changed since the introduction of PHP 5 and MySQL 4.1

What is MySQLi? To correct the issues of MySQL extension, a new extenstion has been created for PHP5 It is called MySQLi It supports all the latest features in MySQL server 4.1 or higher The ‘i’ stands for any one of: improved, interface, ingenious, incompatible or incomplete.

Major Features Procedural Interface An object-oriented interface Support for the new MySQL binary protocol that was introduced in MySQL 4.1. Support for the full feature set of the MySQL C client library

Why Make the Switch? Maintainable Similar Syntax New Interface Advanced Options Speed Security

Let’s see the code! /* Connect to a MySQL Server */ $mysqli = new mysqli('hostname','username','password','database'); if ( mysqli_connect_errno() ) { echo "Connection error. Errorcode: ".mysqli_connect_error(); exit; } /* Close the connection */ $mysqli->close();

How to Run a Query if ($result = $mysqli->query('SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) { /* Fetch the results of the query */ while( $row = $result->fetch_assoc() ){ echo $row['Name']." (". $row['Population'].")\n"; } /* Destroy the result set and free the memory used for it */ $result->close(); } else { echo $mysqli->error; }

Prepared Statements One of the new features of MySQLi Using this feature, it is possible to create queries that are: More secure Have better performance More convenient to write Two types of Prepared Statements: Bound Parameter Bound Result

Bound Parameter Prepared Statements A Query template is created and sent to the MySQL server MySQL server validates it, stores it and returns a special handle for future use When a query needs to be executed, data to fill in the template is sent to the server A complete query is formed and then executed

Advantages The body of the query is sent only once, later only data to fill in are sent Most of the work required to validate and parse the query only needs to be done a single time, instead of each time the query is executed. The data for the query does not need to be passed through a function like mysql_real_escape_string() to ensure that no SQL injection attacks occur. Instead, the sent data is handled safely by server when it is combined with the prepared statement.

Query Structure The '?' placeholders can be used in most places that could have literal data, e.g. a query could be transformed from SELECT Population FROM City WHERE Name = 'Dhaka'; to SELECT Population FROM City WHERE Name = ?; Let’s see a complete example of bound parameter prepared statement

Using Bound Parameter Prepared Statements if( $stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)") ){ $stmt->bind_param('sssd', $code, $language, $official, $percent); $code = 'BAN'; $language = 'Bangla'; $official = 'F'; $percent = 77.8; /* execute prepared statement */ $stmt->execute(); echo $stmt->affected_rows. " Row inserted.\n"; /* close statement and connection */ $stmt->close(); }

The Format String The following table shows the bound varaible types and when to use them: BIND TypeCOLUMN Type i All INT types dDOUBLE and FLOAT b BLOBs sAll other types

Bound Result Prepared Statements Allow the value of variables in a PHP script to be tied to the value of fields of data in a query result set. Create a query Prepare the query Ask the MySQL server to execute the query Bind PHP variables to columns in the query result Request that a new row of data be loaded into the bound variables.

Using Bound Result Prepared Statements if( $stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5") ){ $stmt->execute(); /* bind variables to prepared statement */ $stmt->bind_result($col1, $col2); /* fetch values */ while ($stmt->fetch()) { echo $col1." ". $col2."\n"; } /* close statement */ $stmt->close(); }

Using Bound Parameters and Bound Results Together It is possible to use bound parameters and bound results together in a single prepared statement. Lets see a more complete example that uses both of these

Using Bound Parameters and Bound Results Together if ( $stmt = $mysqli->prepare("SELECT Code, Name FROM Country WHERE Code LIKE ? LIMIT 5") ) { $stmt->bind_param("s", $code); $code = "B%"; $stmt->execute(); /* bind variables to prepared statement */ $stmt->bind_result($col1, $col2); /* fetch values */ while ($stmt->fetch()) { echo $col1." ". $col2."\n"; } /* close statement */ $stmt->close(); }

More Reference

THANK YOU