Database Driven Websites Using PHP with Informix



Similar documents
Developing Perl, PHP, Python, and Ruby on Rails Applications

PHP Skills and Techniques

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

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Learning about Informix and the Open Admin Tool (OAT)

How to use PDFlib products with PHP

PHP Data Objects Layer (PDO) Ilia Alshanetsky

SQL PDO and Microsoft SQL Server

Mac OS X Snow Leopard: IBM Informix IDS PHP 5.3

IBM DB2 for Linux, UNIX, and Windows. Deploying IBM DB2 Express-C with PHP on Ubuntu Linux

Mercury Users Guide Version 1.3 February 14, 2006

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Written by: Johan Strand, Reviewed by: Chafic Nassif, Date: Getting an ipath server running on Linux

MySQL Quick Start Guide

PHP Vulnerabilities in Web Servers

SQL Injection Attack Lab

Getting an ipath server running on Linux

Extending Remote Desktop for Large Installations. Distributed Package Installs

Q&A for Zend Framework Database Access

PHP and XML. Brian J. Stafford, Mark McIntyre and Fraser Gallop

Web Applications Security: SQL Injection Attack

PHP Tutorial From beginner to master

SQL Injection Attack Lab Using Collabtive

Writing MySQL Scripts With Python's DB-API Interface

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

MySQL Quick Start Guide

OpenPro ERP Software Installation Guide Talbert Ave Suite 200 Fountain Valley, CA USA Phone Fax

LAMP Server A Brief Overview

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

OpenPro ERP Software Installation Guide REDHAT LINUX

CCM 4350 Week 11. Security Architecture and Engineering. Guest Lecturer: Mr Louis Slabbert School of Science and Technology.

Using Microsoft Windows Authentication for Microsoft SQL Server Connections in Data Archive

Data Warehouse Center Administration Guide

PHP and Zend Solutions for IBM i

Writing Scripts with PHP s PEAR DB Module

OpenAdmin Tool for Informix (OAT) October 2012

Application note: Connecting the to a Database

MySQL 5.1 INTRODUCTION 5.2 TUTORIAL

About This Document 3. Integration and Automation Capabilities 4. Command-Line Interface (CLI) 8. API RPC Protocol 9.

SQL Injection. Slides thanks to Prof. Shmatikov at UT Austin

SQL and programming languages

Data Access Guide. BusinessObjects 11. Windows and UNIX

Understanding Sql Injection

HOW TO BUILD A VMWARE APPLIANCE: A CASE STUDY

Building Library Website using Drupal

SIMIAN systems. Setting up a Sitellite development environment on Windows. Sitellite Content Management System

Construction of a Web Server with a Database Facility Using Open Source Software

No SQL! no injection? A talk on the state of NoSQL security

Zend Server 5.0 Reference Manual

Build it with Drupal 8

NO SQL! NO INJECTION?

Advanced Web Security, Lab

What will be supplied with chemoventory package?

Writing MySQL Scripts with PHP and PDO

Bubble Code Review for Magento

Virtually Secure. a journey from analysis to remote root 0day on an industry leading SSL-VPN appliance

Nixu SNS Security White Paper May 2007 Version 1.2

Version of this tutorial: 1.06a (this tutorial will going to evolve with versions of NWNX4)

PHP Language Binding Guide For The Connection Cloud Web Services

E-Commerce: Designing And Creating An Online Store

CS346: Database Programming.

Short notes on webpage programming languages

How to Configure Informix Connect and ODBC

SEAGATE BUSINESS NAS ACCESSING THE SHELL. February 1, 2014 by Jeroen Diel IT Nerdbox

Installing Moodle on a Windows x64 Environment

Real SQL Programming 1

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Witango Application Server 6. Installation Guide for OS X

Zend Framework Database Access

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

APACHE. Presentation by: Lilian Thairu

Sugar Open Source Installation Guide. Version 4.5.1

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

Shellshock. Oz Elisyan & Maxim Zavodchik

ITG Software Engineering

Transparent Cryptographic File System for BSD. A primer. Luigi Catuogno [luicat@tcfs.unisa.it]

CTF Web Security Training. Engin Kirda

PHP Case Study on IBM i

Simba XMLA Provider for Oracle OLAP 2.0. Linux Administration Guide. Simba Technologies Inc. April 23, 2013

SQL Injection Protection by Variable Normalization of SQL Statement

Using Caché with ODBC

PHP Batch Jobs on IBM i. Alan Seiden Consulting alanseiden.com

Manage2 API. by: J. Nick Koston

Writing MySQL Scripts with Python DB-API

Installing Microsoft SQL Server Linux ODBC Driver For Use With Kognitio Analytical Platform

SQL Injection 2.0: Bigger, Badder, Faster and More Dangerous Than Ever. Dana Tamir, Product Marketing Manager, Imperva

CN=Monitor Installation and Configuration v2.0

Web Page Redirect. Application Note

PHP ON WINDOWS THE PROS AND CONS OF IMPLEMENTING PHP IN A WINDOWS INFRASTRUCTURE

Architecture and Mode of Operation

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

Spring,2015. Apache Hive BY NATIA MAMAIASHVILI, LASHA AMASHUKELI & ALEKO CHAKHVASHVILI SUPERVAIZOR: PROF. NODAR MOMTSELIDZE

Online shopping store

Accessing External Databases from Mobile Applications

Informix Administration Overview

Transcription:

Database Driven Websites Using PHP with Informix February 12, 2013 Thomas Beebe Advanced DataTools Corp (tom@advancedatatools.com)

Tom Beebe Tom is a Senior Database Consultant and has been with Advanced DataTools for over 10 years. He has been working with Informix since college with a long time fondness for open source languages. Tom is the lead consultant for Networking, Unix System Administration and Web Development needs. Currently, he is the Project Manager and lead developer on a variety of Web Development projects. Contact Info: tom@advancedatatools.com www.advancedatatools.com 703-256-0267 x 106

Introduction To PHP Stands For PHP: Hypertext Preprocessor Started in 1995 by Rasmus Lerdorf as perl scripts Andi Gutmans and Zeev Suraski launched PHP3 in 1997 to replace the dated PHP/FI Started in 1995 as a set of perl scripts Rewritten in 1997 as C PHP3 came in 1998 PHP4 in May 2000 PHP5 in July 2004 Provides a very flexible, expendable application development environment, free to use for any purpose. Large collection of modules and extensions available (mostly free of charge)

Why Use PHP? Fast development time Flexible coding styles Widely supported Extensive support options Free Excellent performance

Run Methods CLI command line Web module: Apache (1/2/2.2) IIS Websphere Iplanet Lighttpd CGI Etc, Etc

Installation Notes Most Linux systems have it in their package repositories Windows installers available Will compile on most any UNIX system. Will compile from source on Windows. Configure is the standard way, use --help

PECL Online package repository. Originally on pear, now moving to pecl Phpize. PDO Informix Drivers Excel and Word support Clucene http://pecl.php.net/

Structure of a PHP File <? <?php echo 'hello world';?> Also: <html><body>hello World<br> <? echo $hello_world;?> </body></html> Can also do: <?=$hello_world?>

Phpize Useful once a system is set up. Can be run from the command line as well. Used to configure the build system for modules

PDO Standardized code and connection methods ODBC can be troublesome The ifx_ driver is not overly stable and is buggy Open source development methodology IBM supported pdo_informix and pdo_ibm drivers Proper error handling

PDO_IBM vs PDO_Informix PDO_IBM is the official direction that IBM is going in PDO_Informix is used by OAT PDO_IBM does not work with lvarchar nor some of the Informix specific functions PDO_Informix has not been updated in several years (last update 11/10/08) Do not co-exist on the same system.

Installing Two ways to install: extensions (php.ini) compiled in ($PHP_SRC/php-x.x.x/ext/ pdo_informix)

Compiling into PHP Download the latest pdo_informix driver Extract it to php_source/ext [it will be PDO_INFORMIX-1.x] Rename it to pdo_informix cd.../buildconf force [this will rebuild configure]./configure help grep informix (make sure it is there)./configure args --with-pdo-informix=$informixdir

Installing From Pecl pecl install pdo_informix Add: Extension=pdo_informix.so to php.ini This will only work if everything is clean.

Manually Build Module Download the latest PDO-Informix from the pecl website Unpack Run 'phpize'./configure; make; make install Edit configure file if needed. Add extension=pdo_informix.so (pdo_informix.dll if on windows)

Dealing With Windows Does not come standard with PHP. Options: Use ODBC Use OAT Find a pre-built dll on a similar system.

PDO Connect This will create a new PDO object named $dbh $dbh = new PDO("informix:DSN=test_odbc, $user, $password); Or: $dbh = new PDO("informix:host=localhost;service=1516;database=stores_demo; server=ifxserver;protocol=onipcshm;enablescrollablecursors=1", $user,$password);

Connection Paramaters $dbh->setattribute($attr,$value); PDO::ATTR_CASE: PDO::CASE_LOWER PDO::CASE_UPPER PDO::CASE_NATURAL PDO::ATTR_ERRMODE: PDO::ERRMODE_SILENT PDO::ERRMODE_WARNING PDO::ERRMODE_EXCEPTION PDO::ATTR_STRINGIFY_FETCHES

PDO Basic Query $sqlline = select count(*) from foo ; $dbh->query($sqlline); Or $dbh->prepare($sqlline); $dbh->execute();

PDO Fetching Data To get a statement handle set a variable to an executed query $sth = $dbh->query($sqlline); To return data do $row = $sth->fetch(pdo::fetch_row); PDO::FETCH_ASSOC PDO::FETCH_BOTH PDO::FETCH_NUM PDO::FETCH_OBJ PDO::FETCH_LAZY

PDO Bound Parameters These make life far easier All data will be inserted properly, no worries about cleaning the data or incorrectly placed quotes Prevents SQL injection attacks. Properly handles newlines Can be bound by placement or by parameter name Faster

Binding on Selects This is required for reading blobs from the database $stmt = $db->prepare("select cat_desc from catalog ); $stmt->execute(); $stmt->bindcolumn(1, $lob, PDO::PARAM_STR); $stmt->fetch(pdo::fetch_bound);

Binding Paramaters LOB needs to be specified, the others are optional but can help maintain proper data types PDO::PARAM_LOB Data Blobs PDO::PARAM_STR Char/Varchar/Text PDO::PARAM_BOOL Bool PDO::PARAM_INT - Integer

PDO Bound Parameters $sqlline = update users set last_ip =? where user_id =? and password =? ; $sth = $dbh->prepare($sqlline); $vars = array($ip, $username, $passwd); $sth->execute($vars);

PDO Bound Parameters $ip = $_SERVER['REMOTE_ADDR']; $username = 'test_user'; $password = 'weakpass'; $sqlline = update users set last_ip = :IP where username = :user and password = :pass ; $sth = $dbh->prepare($sqlline); $sth->bindparam(':ip', $ip, PDO::PARAM_INT); $sth->bindparam(':user', $username); $sth->bindparam(':pass', $password, PDO::PARM_STR, 20); $sth->execute();

PDO Fetch (cont.) fetch() fetchall() fetchcolumn($col_num)

Error Handling PHP 5 introduced try/catch which can be a lifesaver. try { sql stuff here... } catch (PDOException $e) { print "Error!: ". $e->getmessage(); die(); }

Error Handling (cont) $dbh->errorinfo(); Returns an array of the last statement executed 0: Sqlstate Error Code 1: Driver specific error number 2: Driver error message Exception handling variable commands $e->getmessage() = Error message $e->getline() = Line Number $e->getfile() = File that caused the error $e->getcode() = Code the caused the error $e->gettrace() = Array of the error trace

Links http://www.php.net http://framework.zend.com/ http://www.zend.com/ http://www.iiug.org/opensource http://pecl.php.net/package/pdo_informix http://pecl.php.net/package/pdo_ibm http://www.openadmintool.org

Database Driven Websites Using PHP with Informix February 12, 2013 Thomas Beebe Advanced DataTools Corp (tom@advancedatatools.com)