Title: Introduction to PHP Development with IDS
1Introduction to PHP Development with IDS
I13
Tuesday, October 4th 2006 1615
1715. Platform IDS, PHP
2Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
3Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
4Who am I?
- My Unix box usually answers
5Who am I (outside of a Unix box)?
- Jean Georges Perrin
- Development tools (xGL, Java EE, PHP)
- Works with Informix products since 97
- IIUG board member since 02
- Lives in Strasbourg, France
6A little more
- Application developer, started with Visual Basic,
in the early 90s - In the web since 1994
- Move to 4GL in 1997
- Goals
- Webizing all things I touched (business apps,
catalogs and i-4GL) - Find the ease of use of Visual Basic
7And you
- Who knows 4GL?
- Who knows Java?
- Who thinks Java is difficult?
- Who knows PHP?
- Who thinks PHP is easy?
- Who knows .net?
- Who went to my Java lecture earlier this week?
8Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
9Architecture
Data
Application
Database Driver
10Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
11Requirements
- 1 - IDS (from v7.x, but also works on OnLine and
SE) - Where www.iiug.org, www.informix.com
- 2 - PHP (PHP v5.1.4)
- Where www.php.net
- 3 - PDO driver
- Where pecl.php.net , pecl4win.php.net
- 4 - Option Eclipse (v3.2.0)
- Where www.eclipse.org
12Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
13A few words on PHPs history
- PHP stands for PHP Hypertext Processor
- PHP is currently v5
- Not well accepted by serious company
14PHP
fglpc fglgo
- Hello, world in PHP
- Use of PHP CLI
- Code snippets
Source code is between lt?php ?gt markers
A function is a function
lt?php echo "Hello, world..." ?gt
lt?php function main() echo ("Hello,
world...") main() ?gt
DEMO
Hello, world is always the same, in any
language
15PHP Pros Cons
- Procedural Object Oriented (OO) development
- Event driven programming model
- User Interface (UI) Business Logic (BL) tightly
linked - Open architecture, open standards
- General purpose development language
- Becoming a standard
- Looks like hype to some developers
164GL Pros Cons
- Procedural development
- Controlled events
- UI and BL somehow separated (.per .4gl)
- Proprietary solution
- Business apps development language
- Not a standard in industry
- Hard to attract new developers
174GL and PHP
- Weak typing
- Assign an integer to a string
- Not case sensitive
- Well almost not for variables.
- 2 types of string
- parsed strings
- unparsed strings
18Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
19Two ways to access data
- Function calls
- ifx_ and ifxus_ functions
- PHP Data Objects (PDO)
- Set of static methods
- More standard
- Not to be compared to real data objects
- Support for SERIAL in cvs
20PDO The way to go
- Clearly the future of data access in PHP
- Standard way of talking to a database
- Use a connection string, for IBM Informix
db new PDO("informixhostxeoservice1526?da
tabasestores_demoserverol_xeoprotocololsoctcp
?EnableScrollableCursors1DB_LOCALEEN_US.8859-
1 / connection string / , "informix"/ user
/ , "informix"/ password /)
21Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
22Understanding php.ini
- Convenient way to extend PHP.
- Specify you want to use
- PDO
- PDO Informix
extensionphp_pdo.dll extensionphp_pdo_informix
.dll
DEMO
23Your first application using the Command Prompt
- Full source code (copy / paste)
lt?php i 0 db new PDO("informixhostxeose
rvice1526?databasestores_demoserverol_xeopr
otocololsoctcp?EnableScrollableCursors1DB_LOC
ALEEN_US.8859-1 / connection string / ,
"informix"/ user / , "informix"/ password
/) rs db-gtquery("SELECT from
customer") colCount rs-gtcolumnCount() for
(i 0 i lt colCount i) meta
rs-gtgetColumnMeta(i) echo (meta'name' .
"") echo ("\n")
24Your first application (2)
foreach (rs as row) for (i 0 i lt
colCount i) echo (rowi . "")
echo ("\n") ?gt
DEMO
25Running a query
- One method is query
- Code snippet
db new PDO("informixhostxeoservice1526?da
tabasestores_demoserverol_xeoprotocololsoctcp
?EnableScrollableCursors1DB_LOCALEEN_US.8859-
1 / connection string / , "informix"/ user
/ , "informix"/ password /) rs
db-gtquery("SELECT from customer")
Connection
Basic query
26Accessing meta data
- PDO allows you to access Metadata
- Code snippet
colCount rs-gtcolumnCount() for (i 0 i
lt colCount i) meta rs-gtgetColumnMeta(
i) echo (meta'name' . "") echo ("\n")
Column count for the result set
Returns an array containing meta data
Accessing the name parameter of the meta data
27Dumping rows
- Basic browsing thru a result set using foreach
- Code snippet
foreach (rs as row) for (i 0 i lt
colCount i) echo (rowi . "")
echo ("\n") ?gt
28Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
29Your first application using Eclipse
- Create a project
- Add the code
- Run it
DEMO
30Agenda
- Who am I?
- Architecture
- Requirements
- PHP
- Functions vs. PDO
- Your first application using the Command Prompt
- Your first application using Eclipse
- Your first web application
31Your first web application
- The same application, but web
- Strong embedding of HTML tags in the code
DEMO
32Web Source Code
lthtmlgt ltheadgtlttitlegtList of customerslt/titlegtlt/hea
dgt ltbodygt lt?php i 0 db new PDO(
"informixhostxeoservice1526databasestores_de
moserverol_xeoprotocololsoctcpEnableScrollabl
eCursors1DB_LOCALEEN_US.8859-1"/ connection
string / , "informix"/ user / ,
"informix"/ password /) rs
db-gtquery("SELECT from customer") colCount
rs-gtcolumnCount() echo ("lttablegt") echo
("lttheadgtlttrgt") for (i 0 i lt colCount
i) meta rs-gtgetColumnMeta(i) echo
("lttdgt" . meta'name' . "lt/tdgt") echo
("lt/trgtlt/theadgt")
33Web Source Code (2)
echo ("lttbodygt") foreach (rs as row)
//print_r() echo("lttrgt") for (i 0 i lt
colCount i) echo ("lttdgt" . rowi .
"lt/tdgt") echo("lt/trgt") echo
("lt/tbodygtlt/tablegt") ?gt lt/bodygt lt/htmlgt
34Pros Cons
- The strong dependency between business logic and
presentation layer is annoying - Introduction of MVC framework
PHP getting closer and closer to Java!
35Conclusion
- PHP now offers a standard way of accessing data
- PHP is easy
- PHP is rich
- PHP runs
- Command line apps (batch)
- Web apps
- Frameworks are coming (Zend)
36Complexity Features
Difficult
Level of complexity / feature of languages over
time
Easy
2000
2005
1994
2001
2002
2003
2004
2006
1999
1998
1997
1996
1995
37And now
- If you missed my other presentation
Introduction to Java development with IDStoo
bad! - Come to see me in San Jose (May
2007)Introduction to EJB3 dev. with IDS and
Viper - (Give me good marks so I can be selected as best
speaker of the conference and beat Darryl, Lester
and Art - previous speakers).
38And now (seriously)
- Download Eclipse (I guess you all have IDS
already) - Download PHP
- Get a book (OReilly has quite a few great books,
I learnt PHP with PHP for dummies) - Join the development-tools forum on IIUG web site
- Get started with a few examples
39Jean Georges Perrin
I13 Introduction to PHP Development with IDS
- IIUG
- jgp_at_iiug.org
- jgp_at_jgp.net