Overview of PHP MySQL connectors

Similar documents
Advanced Object Oriented Database access using PDO. Marcus Börger

Online Multimedia Winter semester 2015/16

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Switch to MySQLnd Already!

7- PHP and MySQL queries

1. What is SQL Injection?

Q&A for Zend Framework Database Access

Connecting to a Database Using PHP. Prof. Jim Whitehead CMPS 183, Spring 2006 May 15, 2006

PHP Data Objects Layer (PDO) Ilia Alshanetsky

Writing Scripts with PHP s PEAR DB Module

Database Toolkit: Portable and Cost Effective Software

Zend Framework Database Access

A Brief Introduction to MySQL

A table is a collection of related data entries and it consists of columns and rows.

Server side scripting and databases

EOP ASSIST: A Software Application for K 12 Schools and School Districts Installation Manual

Database Extension 1.5 ez Publish Extension Manual

Detecting (and even preventing) SQL Injection Using the Percona Toolkit and Noinject!

SQL Injection. Blossom Hands-on exercises for computer forensics and security

SQL PDO and Microsoft SQL Server

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

SQL Injection Attacks. Prof. Jim Whitehead CMPS 183: Spring 2006 May 17, 2006

Database Driven Websites Using PHP with Informix

SQL Injection Attack Lab Using Collabtive

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

How to Connect to CDL SQL Server Database via Internet

MAMP 3 User Guide! March 2014 (c) appsolute GmbH!

The following steps detail how to prepare your database.

Databases and SQL. The Bioinformatics Lab SS Wiki topic 10. Tikira Temu. 04. June 2013

Sebastian Bergmann. Has instrumentally contributed to tranforming PHP into a reliable platform for large-scale, critical projects.

Jet Data Manager 2012 User Guide

Installing and Configuring MySQL as StoreGrid Backend Database on Linux

Accessing External Databases from Mobile Applications

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

FROM DB TO DB. Manual. Page 1 of 7. Manual. Tel & Fax: info@altiliagroup.com Web:

Develop PHP mobile apps with Zend Framework

The release notes provide details of enhancements and features in Cloudera ODBC Driver for Impala , as well as the version history.

Writing MySQL Scripts with PHP and PDO

CIMHT_006 How to Configure the Database Logger Proficy HMI/SCADA CIMPLICITY

PHP Language Binding Guide For The Connection Cloud Web Services

FileMaker 14. ODBC and JDBC Guide

OpenScape Business V2

SQL Injection Vulnerabilities in Desktop Applications

Facebook Twitter YouTube Google Plus Website

Smart Home Security System Based on Microcontroller Using Internet and Android Smartphone

Log Analyzer Reference

Connect to MySQL or Microsoft SQL Server using R

Abstract. For notes detailing the changes in each release, see the MySQL for Excel Release Notes. For legal information, see the Legal Notices.

SQL and programming languages

Linking Access to SQL Server

IceWarp Server. Log Analyzer. Version 10

Using the Caché SQL Gateway

Transferring Your Hosting Account

Web Programming Step by Step

ODBC Client Driver Help Kepware, Inc.

About This Document 3. About the Migration Process 4. Requirements and Prerequisites 5. Requirements... 5 Prerequisites... 5

Installation and configuration op5 Oracle Extension

The manual contains complete instructions on 'converting' your data to version 4.21.

Expert PHP and MySQL. Application Desscpi and Development. Apress" Marc Rochkind

StoreGrid Backup Server With MySQL As Backend Database:

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

SQL Injection Attack Lab

AdminStudio Release Notes. 16 July Introduction New Features... 6

TECH TUTORIAL: EMBEDDING ANALYTICS INTO A DATABASE USING SOURCEPRO AND JMSL

SQL Injection. SQL Injection. CSCI 4971 Secure Software Principles. Rensselaer Polytechnic Institute. Spring

Beginning MYSQL 5.0. With. Visual Studio.NET 2005

E-Commerce: Designing And Creating An Online Store

McAfee Network Threat Response (NTR) 4.0

Protected Trust Directory Sync Guide

Dream Report Version 4.5

Mac OS X Snow Leopard: IBM Informix IDS PHP 5.3

SQL Injec*on Preven*on. May 3rd 2012

Exam Name: IBM InfoSphere MDM Server v9.0

MySQL Quick Start Guide


INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

Simbirsk Technologies Ltd.

Application note: Connecting the to a Database

Using MySQL for Big Data Advantage Integrate for Insight Sastry Vedantam

Developing an ODBC C++ Client with MySQL Database

G563 Quantitative Paleontology. SQL databases. An introduction. Department of Geological Sciences Indiana University. (c) 2012, P.

Web Development in Java

MYSQL DATABASE ACCESS WITH PHP

Installation and Control in Linux

Oracle PL/SQL Injection

Getting Started with STATISTICA Enterprise Programming

Intended status: Standards Track October 8, 2014 Expires: April 11, 2015

Location-Based Services Using HTML5 Geolocation and Google Maps APIs

TO SQL DB. Manual. Page 1 of 7. Manual. Tel & Fax: info@altiliagroup.com Web:

Synthetic Application Monitoring

Web Application Security Part 1

Role Based Access Control. Using PHP Sessions

OBJECTSTUDIO. Database User's Guide P

Specialized Programme on Web Application Development using Open Source Tools

Put a Firewall in Your JVM Securing Java Applications!

StoreGrid Backup Server With MySQL As Backend Database:

Suite. How to Use GrandMaster Suite. Exporting with ODBC

Transcription:

Overview of PHP MySQL connectors Using the three mysqlnd driver interfaces Justin Swanhart

mysqlnd vs libmysqlclient 2 Compile time decision mysqlnd is the MySQL Native Driver for PHP Introduced in PHP 5.3 Default in PHP 5.4 libmysqlclient requires C client installation and headers

Libmysqlclient warning messages 3 If you choose libmysqlclient the headers should match the compiled version: PHP Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50537 Library:50622 in /home/justin/t.php on line 15

PHP API choices 4 There are three MySQL API choices All three work with mysqlnd and libmysqlclient Choices are Legacy mysql functions mysqli extension PDO_MySQL

Available API choices 5 Legacy mysql API This is the original MySQL API for PHP Many older applications written in this API Not recommended few new development (this API is officially deprecated)

Why not use a deprecated interface? 6 Will be removed in the future Does not support all features of mysqlnd No object-oriented interface

Example mysql API program 7 <?php $sql = <<<EOF select FlightDate, UniqueCarrier, TailNum, FlightNum, OriginAirportID, DestAirportID from demo.ontime limit 2; EOF; Output $conn =mysql_connect('localhost','root','password'); if(!$conn) { echo mysql_error(). "\n"; exit(-1); $stmt = mysql_query($sql, $conn); if(!$stmt) { echo mysql_error($conn). "\n"; while($row = mysql_fetch_assoc($stmt)) { print_r($row); Array ( [FlightDate] => 2010-10-14 [UniqueCarrier] => DL [TailNum] => N921DL [FlightNum] => 1 [OriginAirportID] => 11193 [DestAirportID] => 12478 ) Array ( [FlightDate] => 2010-10-14 [UniqueCarrier] => DL [TailNum] => N698DL [FlightNum] => 3 [OriginAirportID] => 14869 [DestAirportID] => 12478 )

Useful functions 8 mysql_close mysql_insert_id mysql_fetch_array mysql_real_escape_string mysql_select_db mysql_unbuffered_query

mysqli extension 9 Dual interface Procedural (function) based interface Object-oriented interface

Procedural interface 10 $conn = mysqli_connect('localhost','root','password','demo'); if (mysqli_connect_errno($conn)) { echo "Failed to connect to MySQL: ". mysqli_connect_error(); exit(-1); $stmt = mysqli_query($conn, $sql); if(!$stmt) { echo mysqli_error($conn). "\n"; exit(-1); while($row = mysqli_fetch_assoc($stmt)) { print_r($row);

mysqli object-oriented interface 11 $conn = new mysqli('localhost','root','password','demo'); if($conn->connect_errno) { echo $mysqli->connect_error. "\n"; exit(-1); $stmt = $conn->query($sql); if(!$stmt) { echo $conn->error. "\n"; exit(-1); while($row = $stmt->fetch_assoc()) { print_r($row);

Prepared statements 12 if (!($stmt = $mysqli->prepare("insert INTO tbl(id) VALUES (?)"))) { echo $mysqli->error. "\n"; exit(-1); $id = 9; if (!$stmt->bind_param("i", $id)) { echo $stmt->error. "\n"; exit(-1); if (!$stmt->execute()) { echo "Execute failed: (". $stmt->errno. ") ". $stmt->error;

Useful functions/members 13 mysqli::set_charset mysqli::real_escape_string mysqli::$insert_id mysqli::begin_transaction mysql::commit mysql::select_db

PDO / PDO_MySQL 14 PDO (PHP Data Objects) is a consistent objectoriented database abstraction layer to multiple database drivers Does not provide missing SQL features, you must use cross-platform SQL PDO_MySQL is the MySQL interface for PDO

Connecting with PDO 15 Uses a DSN: $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; try { $conn = new PDO($dsn, 'root'], 'password', array(pdo::mysql_attr_local_infile => 1)); catch (PDOException $e) { echo 'Connection failed: '. $e->getmessage(); return false;

Using buffered queries 16 $conn- >setattribute(pdo::mysql_attr_use_buffered_query, true); try{ $stmt = $conn->query($sql); catch {

Using unbuffered queries 17 $conn->setattribute(pdo::mysql_attr_use_buffered_query, false); try{ $stmt = $conn->query($sql); catch {

Fetching results 18 As array with column names $r = $stmt->fetch(pdo::fetch_assoc); Numerically indexed $r = $stmt->fetch(pdo::fetch_num);

Example wrapper for PDO 19 The Shard-Query DAL (Simple-DAL) wraps around PDO, using legacy mysql like functions but also providing OO interface support One single object for all actions, unlike PDO or mysqli

Simple-DAL 20 $server=array('host'=>localhost,'user'=>'root','password'=>'pass','db'=>'demo'); $conn = SimpleDAL::factory($server); if($conn->my_error()){ die($conn->my_error(). "\n"); $stmt = $conn->my_query($sql); while($row = $conn->my_fetch_assoc($stmt)) { or $conn->my_query($sql); while($row = $conn->my_fetch_assoc()) { https://github.com/greenlion/swanhart-tools/tree/master/shard-query/include/dal