Beginners Guide to Web-Enabling your Informix database Using : By: Peter Schmidt PRS Technologies, Inc.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

1 Database Driven Web Application Clients Application Servers including web servers Database Server Traditional client-server (2-tier architecture): client:
PHP Programming with MySQL Slide 2-1 CHAPTER 2 Getting Started with PHP.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
Guide To UNIX Using Linux Third Edition
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
Linux Operations and Administration
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Nael Alian Introduction to PHP
PHP With Oracle 11g XE By Shyam Gurram Eastern Illinois University.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Introduction to PHP.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Introduction PHP is a server-side scripting language.
Database Connectivity and Server-Side Scripting Chapter 12.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using 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.
: Information Retrieval อาจารย์ ธีภากรณ์ นฤมาณนลิณี
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
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.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
A pache M ySQL P hp Robert Mudge Reference:
Web Database Programming Using PHP
Introduction to Dynamic Web Programming
Web Database Programming Using PHP
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP Introduction.
PHP.
IntroductionToPHP Static vs. Dynamic websites
Tutorial 6 PHP & MySQL Li Xu
Introduction to PHP.
Presentation transcript:

Beginners Guide to Web-Enabling your Informix database Using : By: Peter Schmidt PRS Technologies, Inc.

PRS Technologies, Inc. October, What is PHP ? PHP (officially "PHP: Hypertext Preprocessor") ( Originally “Personal Home Page” ) A server-side HTML-embedded scripting language. Writing a database-enabled web page is incredibly simple ! PHP is in use on over 150,000 sites around the world. Since PHP is executed on the web server, web browsers can’t see your PHP code. PHP is very fast. PHP is completely free (Open Source) PHP (officially "PHP: Hypertext Preprocessor") ( Originally “Personal Home Page” ) A server-side HTML-embedded scripting language. Writing a database-enabled web page is incredibly simple ! PHP is in use on over 150,000 sites around the world. Since PHP is executed on the web server, web browsers can’t see your PHP code. PHP is very fast. PHP is completely free (Open Source)

PRS Technologies, Inc. October, The following databases are currently supported: Informix InterBasePostgreSQL dBaseFrontBaseSolid EmpressmSQLSybase FilePro ( read-only )Direct MS-SQLUnix dbm IBM DB2MySQLAdabas D ODBCVelocisIngres Oracle (OCI7 and OCI8) Informix InterBasePostgreSQL dBaseFrontBaseSolid EmpressmSQLSybase FilePro ( read-only )Direct MS-SQLUnix dbm IBM DB2MySQLAdabas D ODBCVelocisIngres Oracle (OCI7 and OCI8)

PRS Technologies, Inc. October, An introductory example of PHP <?php echo "Hi, I'm a PHP script!"; ?> Note that PHP code is embedded inside the HTML code. Demo 1

PRS Technologies, Inc. October, Here I am in HTML! <?php echo ”Now I'm in PHP! "; ?> Back to HTML! HTML PHP Back to HTML Note the PHP start and stop tags Demo 2 PHP code is executed on the web server! Switching between HTML and PHP

PRS Technologies, Inc. October, Putting comments in PHP code <?php echo "This is a test "; // This is a one-line c++ style comment echo "This is a test "; # This is Unix shell-style style comment /* This is the first line of a multi line comment This is the second line of comment */ ?> PHP supports 'C', 'C++' and Unix shell-style comments.

PRS Technologies, Inc. October, Connecting to the Informix database <?php $database = "video";/* populate variables */ $server = "lapdog_tcp"; $login = ”username"; $password = ”password"; $dbs = $database. $server; /* concatenate */ $connect_id = ifx_pconnect($dbs,$g_login,$g_password); if (!$connect_id) { echo "Unable to connect to Informix database \n"; chk_ifx_err1($connect_id); } else { echo “Informix connection successful! ”; } ?> Demo 3 This is my user defined function

PRS Technologies, Inc. October, <?php $database = "video"; $server = "lapdog_tcp"; $login = ”username"; $password = ”password"; ?> Demo 3 Use a tcp/ip connection to the database (vs. a shared memory connection) Warning: E [SQLSTATE=IX 000 SQLCODE=-27000] in /u/www/lapdog/php_demo/php_demo4.php3 on line 40 Unable to connect to Informix database Informix error: Cannot support multiple connections over shared memory. finderr Cannot support multiple connections over shared memory. An application cannot use the CONNECT statement to make more than one connection that uses shared-memory communication (IPC). Ensure that the application makes only one shared-memory connection at a time. If the application must use concurrent connections, the database server administrator might need to change the connection type (as specified in the nettype field of the sqlhosts file) from a shared -memory connection to a network connection. Use a tcp/ip connection to avoid error

PRS Technologies, Inc. October, Persistent database connections An SQL connection that does not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the connection. if connection overhead is high, persistent connections help you considerably. It may (and probably will) change the efficiency of the script, but should not change its behavior! An SQL connection that does not close when the execution of your script ends. When a persistent connection is requested, PHP checks if there's already an identical persistent connection (that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the connection. if connection overhead is high, persistent connections help you considerably. It may (and probably will) change the efficiency of the script, but should not change its behavior! $connect_id = ifx_pconnect();

PRS Technologies, Inc. October, <?php function chk_ifx_err1($result_id) { $err_string = ifx_error($result_id); /* Note: error If 1st character of err_string is not blank */ if ($err_string[0] != ' ') { printf("Informix error: %s", ifx_errormsg()); die; } ?> Warning: E [SQLSTATE=IX 000 SQLCODE=-952] in /u/www/lapdog/php_demo/php_demo4.php3 on line 40 Unable to connect to Informix database Informix error: User's password is not correct for the database server. Demo 4 Get the error string Check for blank User defined function End program Reporting an Informix error

PRS Technologies, Inc. October, <?php if ($connect_id) { $statmt_txt = "select count(*) count from vhs where type_code = 'ST1' "; $statmt_id1 = ifx_query($statmt_txt,$connect_id); // EXECUTE SQL if (!$statmt_id1) { chk_ifx_err1($statmt_id1); } // CHECK FOR ERROR $row = ifx_fetch_row($statmt_id1); // FETCH RESULT OF COUNT INTO ARRAY if (!$row) { chk_ifx_err1($statmt_id1); } // CHECK FOR ERROR $num_rows_selected = sprintf("%d",$row[count]); // FORMAT COUNT echo " "; echo "$num_rows_selected rows selected "; // DISPLAY RESULT IN HTML echo " "; } ?> Demo 5 Selecting a count from a table

PRS Technologies, Inc. October, <?php $statmt_txt = " select tape_num Tape_Number,title from vhs where type_code = 'ST1' order by title "; $statmt_id = ifx_prepare($statmt_txt,$connect_id,IFX_SCROLL); // PREPARE if (!$statmt_id) { chk_ifx_err1($statmt_id); }// CHECK FOR ERROR $ret_val = ifx_do($statmt_id); // EXECUTE PREPARED STATEMENT if (!$ret_val) { chk_ifx_err1($statmt_id); }// CHECK FOR ERROR ifx_htmltbl_result ($statmt_id, "BORDER='1' CELLSPACING=0 CELLPADDING=2 BGCOLOR='cornsilk' ALIGN=center"); ?> Demo 6 See output on next slide Use display label for clarity Selecting rows Output to a HTML table.

PRS Technologies, Inc. October, Result from using: ifx_htmltbl_result Demo 6

PRS Technologies, Inc. October, <?php $statmt_txt = " select * from vhs where type_code = 'ST1' order by title "; $statmt_id = ifx_prepare($statmt_txt,$connect_id,IFX_SCROLL); // PREPARE if (!$statmt_id) { chk_ifx_err1($statmt_id); }// CHECK FOR ERROR $ret_val = ifx_do($statmt_id); // EXECUTE PREPARED STATEMENT if (!$ret_val) { chk_ifx_err1($statmt_id); }// CHECK FOR ERROR echo ”; // HTML Demo Continued on next slide --- Selecting rows using a cursor slide 1 of 2

PRS Technologies, Inc. October, while ($row = ifx_fetch_row($statmt_id, ”NEXT” )) { $serial_id= $row[serial_id]; $type_code= chop($row[type_code]); $tape_num= $row[tape_num]; $title= chop($row[title]); $hours= $row[hours]; $comment= chop($row[comment]); echo " \n"; echo " $serial_id "; echo " $type_code "; echo " $tape_num "; echo " $title "; echo " $hours "; echo " $comment "; echo " "; } echo " "; ?> Demo Continued from previous slide --- Create an “associative” array named “row”. Use column names to identify fields. Use “chop” to remove trailing blanks if desired. Populate fields from associative array Selecting rows using a cursor slide 2 of 2

PRS Technologies, Inc. October, <?php $statmt_txt = " select * from vhs where type_code = ? order by title "; ?> Demo 7 “placeholders” are currently not supported, but you can do this instead. <?php $my_code = “ST1”; $statmt_txt = " select * from vhs where type_code = ’ $my_code ' order by title "; ?> Invalid statement valid statement Can’t use placeholders

PRS Technologies, Inc. October, Tape Number: <?php echo “The tape number is: $tape_num ”; ?> Variables from outside PHP HTML Forms (GET and POST)

PRS Technologies, Inc. October, <?php if ($connect_id) { $sql_txt = "insert into vhs (serial_id, type_code, tape_num, title) values "; $sql_txt.= ” ($serial_id, \”$type_code\”, $tape_num, \”$title\”) "; $ret_val = ifx_query($sql_txt,$connect_id); // INSERT RECORD if (!$ret_val) { chk_ifx_err1($statmt_id); }// CHECK FOR ERROR } ?> Inserting a row

PRS Technologies, Inc. October, <?php $input_array = array ( "type_code" => $type_code, "tape_num" => $tape_num, "title" => $title, "hours" => $hours, "comment" => $comment ); ?> An associative array is an array which uses a string (instead of a number) to locate an element within the array. Creating an associative array

PRS Technologies, Inc. October, <?php $type_code_array = array ( "MOVIE" => "Movies", "DS9" => "Deep Space 9", "ST1" => "Star Trek (Original)", "ST2" => "Star Trek the Next Generation", "VOY" => "Star Trek Voyager", "HOME" => "Home Movies", "MAX" => "Max Headroom", "OTHER" => "Other" ); echo “ Choose Type of Video”; while (list($key,$value) = each($type_code_array)) { if ($key == $type_code) { echo " $value\n"; } else { echo " $value\n"; } echo " ”; ?> Create an associative array of type codes Step through the array Stepping through an associative array

PRS Technologies, Inc. October, <?php if (preg_match("/\|/",$query_string)) {// Search $query_string for a pipe … your code here … // Do this if pipe was found } ?> Search a string for the presence of a pipe symbol Perform a regular expression match on a string. Return (true) if match was positive. The syntax for the pattern search closely resembles Perl. Perform a regular expression match on a string. Return (true) if match was positive. The syntax for the pattern search closely resembles Perl. Searching a string for a pattern Perl-compatible Regular Expression functions

PRS Technologies, Inc. October, <?php $query_string = “ 123 | 456 | 789 “; $pipe_list = preg_split("/\|/",$query_string); // Create an array of strings while ( list($key,$value) = each($pipe_list)) { // for each element in the array... … your code here … ?> Create an array from pipe demimited string Split string by a regular expression. Returns an array containing substrings. The syntax closely resembles Perl. Split string by a regular expression. Returns an array containing substrings. The syntax closely resembles Perl. Creating an array from a pipe-delimited string Perl-compatible Regular Expression functions

PRS Technologies, Inc. October, <?php function cnt_and_query ($table_name,$where_clause) { … more php code here … return array ($statmt_id2,$num_rows_selected); } ?> <?php list($statmt_id,$cnt_found) = cnt_and_query("vhs",$where_clause); ?> Call a function Start function End function Return multiple values Call a function passing and returning variables

PRS Technologies, Inc. October, <?php require("common.inc"); require("menu.inc"); require("display_form.inc"); require("query.inc"); require("add.inc"); require("modify.inc"); ?> Use include() and require() to reference program modules. With include, statements are re-evaluated each time - almost like calling a function. With require, statements are replaced by the required file when it is first encountered. Good for user defined functions. Use include() and require() to reference program modules. With include, statements are re-evaluated each time - almost like calling a function. With require, statements are replaced by the required file when it is first encountered. Good for user defined functions. Breaking your program up into logical modules

PRS Technologies, Inc. October, Scope of variables Scope spans the entire module, including “included” and “required” files. Variables defined outside of a function, can be referenced inside the function, if defined as globally available. Any variable defined inside a function can only be used within that function, unless specifically defined as globally available in that function. Globals can also be accessed via the special “GLOBALS” array. See “demo8” for examples. Scope spans the entire module, including “included” and “required” files. Variables defined outside of a function, can be referenced inside the function, if defined as globally available. Any variable defined inside a function can only be used within that function, unless specifically defined as globally available in that function. Globals can also be accessed via the special “GLOBALS” array. See “demo8” for examples. Demo 8 global $variable5; $dbs = $GLOBALS["DATABASE"];

PRS Technologies, Inc. October, Installing PHP PHP (without Informix) is usually available on most Linux and Apache installations using ODBC. Configuring PHP to use Informix is NOT a cakewalk. Requires use of ESQL/C libraries to compile (free w/Client SDK). Don’t reuse previous versions of Apache httpd.conf if you are upgrading Apache from a earlier version. If you want the database to reside in a machine separate from the web server, you will need Informix Client SDK or I- Connect on the web server. If you're using I-Connect on the deployment machine, you must compile on a machine with ClientSDK installed. And CSDK and I-Connect need to be in the same directory on the two different machines. PHP (without Informix) is usually available on most Linux and Apache installations using ODBC. Configuring PHP to use Informix is NOT a cakewalk. Requires use of ESQL/C libraries to compile (free w/Client SDK). Don’t reuse previous versions of Apache httpd.conf if you are upgrading Apache from a earlier version. If you want the database to reside in a machine separate from the web server, you will need Informix Client SDK or I- Connect on the web server. If you're using I-Connect on the deployment machine, you must compile on a machine with ClientSDK installed. And CSDK and I-Connect need to be in the same directory on the two different machines.

PRS Technologies, Inc. October, Aquire or download the software. Unpack Apache and PHP tar-balls. Set your Informix environmentals. Pre-Configure Apache. Configure, compile and install PHP Configure, compile and install Apache. Update Apache startup script with Informix environment Update Apache httpd.conf Re-start Apache web server. Test. Aquire or download the software. Unpack Apache and PHP tar-balls. Set your Informix environmentals. Pre-Configure Apache. Configure, compile and install PHP Configure, compile and install Apache. Update Apache startup script with Informix environment Update Apache httpd.conf Re-start Apache web server. Test. Installing PHP with Apache Overview

PRS Technologies, Inc. October, Go to Click on: downloads Click on: Complete Source Code PHP August 2000 Go to Click on apache server. Click on download. Click on apache_ tar.gz Go to Click on: downloads Click on: Complete Source Code PHP August 2000 Go to Click on apache server. Click on download. Click on apache_ tar.gz Installing PHP with Apache Aquire or download the software

PRS Technologies, Inc. October, cd /usr/local gunzip apache_ tar.gz tar xvf apache_ tar gunzip php tar.gz tar xvf php tar Installing PHP with Apache Unpack Apache and PHP tar-balls

PRS Technologies, Inc. October, INFORMIXDIR=/opt/informix INFORMIXSERVER=myserver_shm ONCONFIG=onconfig.myserver PATH=$PATH:$INFORMIXDIR/bin LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql export INFORMIXDIR INFORMIXSERVER ONCONFIG LD_LIBRARY_PATH Don’t forget this one! Installing PHP with Apache Set your Informix environmentals Optional

PRS Technologies, Inc. October, cd apache_ /configure --prefix=/usr/local/apache cd.. Installing PHP with Apache Pre-Configure Apache

PRS Technologies, Inc. October, cd php /configure --with-apache=../apache_ with-informix=$INFORMIXDIR make make install cd.. Installing PHP with Apache Configure, compile and install PHP

PRS Technologies, Inc. October, cd apache_ /configure --prefix=/usr/local/apache \ --enable-module=rewrite \ --enable-shared=rewrite \ --enable-module=most \ --enable-shared=max \ --enable-module=so \ --activate-module=src/modules/php4/libphp4.a \ --enable-module=php4 make make install cd.. Installing PHP with Apache Configure, compile and install Apache

PRS Technologies, Inc. October, cd /etc/rc.d/init.d On Linux, update the apache start-up script “httpd” to include the Informix environment. Or use apachectl. (Varies by platform.) On Linux, update the apache start-up script “httpd” to include the Informix environment. Or use apachectl. (Varies by platform.) Installing PHP with Apache Update Apache startup script with Informix environment

PRS Technologies, Inc. October, cd /usr/local/apache/conf Update the apache configuration file “httpd.conf”. If you have upgraded Apache from a different version, do not use the previous “httpd.conf” file as a basis for the new one. Update the apache configuration file “httpd.conf”. If you have upgraded Apache from a different version, do not use the previous “httpd.conf” file as a basis for the new one. AddModule mod_php4.c AddType application/x-httpd-php4.php4 AddType application/x-httpd-php4-source.phps Installing PHP with Apache Update Apache httpd.conf

PRS Technologies, Inc. October, cd /etc/rc.d/init.d./httpd restart Installing PHP with Apache Re-start Apache web server apachectl apachectl configtest Also, you can use: On Linux:

PRS Technologies, Inc. October, (downloads section) This presentation Entire source of videotape demo Source of all examples Tech-Notes article on PHP by Mario Estrada Monterey Peninsula Ski Club - Cabin Reservation System by Jonathan Leffler (downloads section) This presentation Entire source of videotape demo Source of all examples Tech-Notes article on PHP by Mario Estrada Monterey Peninsula Ski Club - Cabin Reservation System by Jonathan Leffler PHP Resources PRS Technologies, Inc.