php and rich internet applications

47
PHP and Rich Internet Applications Mike Potter http://www.riapedia.com / [email protected]

Upload: elliando-dias

Post on 24-May-2015

2.806 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: PHP and Rich Internet Applications

PHP and Rich Internet Applications

Mike Potterhttp://www.riapedia.com/[email protected]

Page 2: PHP and Rich Internet Applications

Fast

Easy

Page 3: PHP and Rich Internet Applications

<?php

if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {

!! echo 'Could not connect to mysql';

!! exit;

}

if (!mysql_select_db('mysql_dbname', $link)) {

!! echo 'Could not select database';

!! exit;

}

$sql! ! = 'SELECT foo FROM bar WHERE id = 42';

$result = mysql_query($sql, $link);

if (!$result) {

!! echo "DB Error, could not query the database\n";

!! echo 'MySQL Error: ' . mysql_error();

!! exit;

}

mysql_free_result($result);

return($result);

?>

Page 4: PHP and Rich Internet Applications

function PMA_getSearchSqls($table, $search_str, $search_option)

{

global $err_url, $charset_connection;

// Statement types $sqlstr_select = 'SELECT';

$sqlstr_delete = 'DELETE';

// Fields to select $res = PMA_DBI_query('SHOW ' . (PMA_MYSQL_INT_VERSION >= 40100 ? 'FULL ' : '') . 'FIELDS FROM ' . PMA_backquote($table) . '

FROM ' . PMA_backquote($GLOBALS['db']) . ';');

while ($current = PMA_DBI_fetch_assoc($res)) {

if (PMA_MYSQL_INT_VERSION >= 40100) {

list($current['Charset']) = explode('_', $current['Collation']);

}

$current['Field'] = PMA_backquote($current['Field']);

$tblfields[] = $current;

} // while PMA_DBI_free_result($res);

unset($current, $res);

$tblfields_cnt = count($tblfields);

// Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table);

// Beginning of WHERE clause $sqlstr_where = ' WHERE';

$search_words = (($search_option > 2) ? array($search_str) : explode(' ', $search_str));

$search_wds_cnt = count($search_words);

$like_or_regex = (($search_option == 4) ? 'REGEXP' : 'LIKE');

$automatic_wildcard = (($search_option <3) ? '%' : '');

for ($i = 0; $i < $search_wds_cnt; $i++) {

// Eliminates empty values // In MySQL 4.1, if a field has no collation we get NULL in Charset // but in MySQL 5.0.x we get '' if (!empty($search_words[$i])) {

for ($j = 0; $j < $tblfields_cnt; $j++) {

if (PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL' &&

$tblfields[$j]['Charset'] != '') {

$prefix = 'CONVERT(_utf8 ';

$suffix = ' USING ' . $tblfields[$j]['Charset'] . ') COLLATE ' . $tblfields[$j]['Collation'];

} else {

$prefix = $suffix = '';

}

$thefieldlikevalue[] = $tblfields[$j]['Field']

. ' ' . $like_or_regex . ' '

Page 5: PHP and Rich Internet Applications
Page 6: PHP and Rich Internet Applications

www.riapedia.com

Page 7: PHP and Rich Internet Applications
Page 8: PHP and Rich Internet Applications

RIA Characteristics

• Full applications

• Could replace desktop apps

• Applications, not web pages

Page 9: PHP and Rich Internet Applications
Page 10: PHP and Rich Internet Applications
Page 11: PHP and Rich Internet Applications

What’s in it

for me?for my employer?

Page 12: PHP and Rich Internet Applications

Rich Internet Applications are the next evolution of the web.

Source: Gartner Research, May 11, 2005

Page 13: PHP and Rich Internet Applications

Builds on existing skills and knowledge

Page 14: PHP and Rich Internet Applications

$

Page 15: PHP and Rich Internet Applications

Saved ~160 GB in 3 hrs

Page 16: PHP and Rich Internet Applications

User experience matters

Page 17: PHP and Rich Internet Applications

Client Options

• Ajax (In Browser)

• Java (Sun)

• XUL (Mozilla)

• XAML (Microsoft)

• MXML (Adobe Flex)

Page 18: PHP and Rich Internet Applications

Ajax Examples

Page 19: PHP and Rich Internet Applications

XUL Examples

Page 20: PHP and Rich Internet Applications

XUL Examples

Songbird

Page 21: PHP and Rich Internet Applications

XAML Examples

Page 22: PHP and Rich Internet Applications
Page 23: PHP and Rich Internet Applications
Page 24: PHP and Rich Internet Applications
Page 25: PHP and Rich Internet Applications
Page 26: PHP and Rich Internet Applications

To Think About

• Reach - How many people will view this application? What platform will they be on? Is it an open or closed platform?

• Rich - Can I integrate rich content easily, like video, audio and animations?

• Tools - What will I use to build this application? How will I debug?

Page 27: PHP and Rich Internet Applications

PHP and RIAs

• Read in XML from a PHP backend (REST)

Page 28: PHP and Rich Internet Applications

REST with PHP<?php

//connect to the databasemysql_connect ...

//get the datamysql_query( “SELECT * from recipes”);...

//transform into XML

print “<recipes><recipe id=’1’ name=’cake’/><recipe id=’2’ name=’hotdog’/></recipes>”;

?>

Page 29: PHP and Rich Internet Applications
Page 30: PHP and Rich Internet Applications
Page 31: PHP and Rich Internet Applications

PHP and RIAs

• Transfer PHP objects to the client directly

• JSON - JavaScript Object Notation

• AMF - ActionScript Messaging Format

Page 32: PHP and Rich Internet Applications

JSON and PHP

Page 33: PHP and Rich Internet Applications
Page 34: PHP and Rich Internet Applications
Page 35: PHP and Rich Internet Applications
Page 36: PHP and Rich Internet Applications
Page 37: PHP and Rich Internet Applications

Flex with AMFPHP

<?php

//connect to the databasemysql_connect ...

//get the data$ResultObject = mysql_query( “SELECT * from recipes”);...

return( mysql_fetch_object( $ResultObject ) );

?>

Page 38: PHP and Rich Internet Applications

How to make money?

Page 39: PHP and Rich Internet Applications

How to make money?

Page 40: PHP and Rich Internet Applications

Recap

• Build PHP apps as services that can be used by any front end - Ajax, XAML, Flex etc...

• Rich clients and components allow you to simplify your PHP code

Page 41: PHP and Rich Internet Applications

What’s next?

Page 42: PHP and Rich Internet Applications

Web Compiler for Flex Applications

• http://labs.adobe.com

• Allows you to create MXML, ActionScript, upload to the server and compile there, similar to developing PHP applications

Page 43: PHP and Rich Internet Applications
Page 44: PHP and Rich Internet Applications

• O!ine / Occasionally Connected

• Applications can run in background

• Network

• HTTP

• XML-RPC / SOAP / Rest based web services

• Binary and XML sockets

• File I/O

• Local storage / Settings API

• Custom Chrome

• Shape

• Alpha

Apollo enables...

Page 45: PHP and Rich Internet Applications
Page 46: PHP and Rich Internet Applications
Page 47: PHP and Rich Internet Applications

THANK YOU!