php development with oracle pt 2
TRANSCRIPT
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 1/14
PHP Development with OracleBy Darun
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 2/14
Creating and Editing PHP Scripts
� There are a number of specialized PHP editors available,
including Oracles JDeveloper which can be configured with
a PHP extension.
� Many developers still prefer text editors, or editors with
modes that highlight code syntax and aid development.
� PHP scripts often have the file extension .php, butsometimes .phtml or .inc are also used.
� The web server can be configured to recognize the
extension(s) that you choose.
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 3/14
PHP Syntax Overview
� PHP scripts are enclosed in <?php and ?> tags.Lines are terminated with a semi-colon:
� Blocks of PHP code and HTML code may beinterleaved. The PHP code can also explicitly printHTML tags:
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 4/14
PHP Syntax Overview
� The output when running this script is:
� A browser would display it as:
� PHP strings can be enclosed in single or doublequotes:
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 5/14
PHP Syntax Overview
� Variable names are prefixed with a dollar sign.Things that look like variables inside a double-quoted string will be expanded:
� Strings and variables can also be concatenatedusing a period.
� Variables do not need types declared:
� Arrays can have numeric or associative indexes:
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 6/14
PHP Syntax Overview
� Strings and variables can be displayed with anecho or print statement. Formatted output with printf() is also possible.
� Code flow can be controlled with tests and loops.PHP also has a switch statement. The if/ elseif/ else
statements look like:
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 7/14
PHP Syntax Overview
� A traditional loop is:
� This prints the numbers 0 to 9, each on a new line.
The value of $i is incremented in each iteration.The loop stops when the test condition evaluatesto true. You can also loop with while or do whileconstructs.
� The foreach command is useful to iterate overarrays:
� This sets $v to each element of the array in turn.
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 8/14
PHP Syntax Overview
� A function may be defined:
� Functions may have variable numbers of
arguments. This function could be called using:
� Function calls may appear earlier than thefunction definition. Procedures use the samefunction keyword but do not have a return
statement.
� Sub-files can be included in PHP scripts with aninclude() or r equir e() statement.
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 9/14
PHP Syntax Overview
� A r equir e() will generate a fatal error if the script isnot found. The include_once() and r equir e_once()statements prevent multiple inclusions of a file.
� Comments are either single line:
� or multi-line:
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 10/14
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 11/14
Running PHP Scripts
� Values can be changed by editing php.ini or using the Zend
Core for Oracle console, and restarting the web server. Somevalues can also be changed within scripts by using theini_set() function.
� To connect to Oracle, some Oracle environment variables
need to be set before the web server starts.
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 12/14
Running PHP Scripts in a Browser
� PHP scripts are commonly run by loading them ina browser:
http:// l ocal host/myphpinfo.php
� If your PHP code is in a file
� The -h options gives the help text:
� Common options when first using PHP are --ini which displays the location of the php.ini file, and-i which displays the value of the php.ini settings.
R
unning Scripts with Command Line PHP
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 13/14
Debugging PHP Scripts
� If not using a specialized PHP editor, debuggingwill be an old-fashioned matter of using echo toprint variables and check code flow.
�The v ar _dump() function is useful for debuggingbecause it formats and prints complex variables:
� The output is:
� The formatting is apparent when using command-line PHP. In a browser, to prevent white space andnew lines coalescing, you will need to do:
8/7/2019 PHP Development with Oracle Pt 2
http://slidepdf.com/reader/full/php-development-with-oracle-pt-2 14/14
END