0% found this document useful (0 votes)
34 views14 pages

PHP Development With Oracle PT 2

This document provides an overview of PHP syntax and how to run PHP scripts. It discusses PHP editors, syntax elements like variables and arrays, flow control like if/else statements, functions, and includes. It also covers running PHP scripts in a browser or from the command line, debugging techniques, and connecting PHP to Oracle.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views14 pages

PHP Development With Oracle PT 2

This document provides an overview of PHP syntax and how to run PHP scripts. It discusses PHP editors, syntax elements like variables and arrays, flow control like if/else statements, functions, and includes. It also covers running PHP scripts in a browser or from the command line, debugging techniques, and connecting PHP to Oracle.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

PHP Development with Oracle

By Darun
Creating and Editing PHP Scripts
• There are a number of specialized PHP editors available, including
Oracle’s 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, but sometimes
.phtml or .inc are also used.

• The web server can be configured to recognize the extension(s)


that you choose.
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 be


interleaved. The PHP code can also explicitly print
HTML tags:
PHP Syntax Overview
• The output when running this script is:

• A browser would display it as:

• PHP strings can be enclosed in single or double


quotes:
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 concatenated


using a period.

• Variables do not need types declared:

• Arrays can have numeric or associative indexes:


PHP Syntax Overview

• Strings and variables can be displayed with an


echo 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:
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 evaluates to true.
You can also loop with while or do while constructs.

• The foreach command is useful to iterate over arrays:

• This sets $v to each element of the array in turn.


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 the function


definition. Procedures use the same function
keyword but do not have a return statement.

• Sub-files can be included in PHP scripts with an


include() or require() statement.
PHP Syntax Overview
• A require() will generate a fatal error if the script
is not found. The include_once() and
require_once() statements prevent multiple
inclusions of a file.

• Comments are either single line:

• or multi-line:
Running PHP Scripts
• PHP scripts can be loaded in a browser, or executed at a
command prompt in a terminal window.

• Browsers will interpret HTML tags and compress white space


including new-lines, script output can differ between
command-line and browser invocation of the same script.

• Many aspects of PHP are controlled by settings in the php.ini


configuration file.

• The location of the file is system specific. Its location, the list
of extensions loaded, and the value of all the initialization
settings can be found using the phpinfo() function:
Running PHP Scripts

• Values can be changed by editing php.ini or using the Zend


Core for Oracle console, and restarting the web server. Some
values can also be changed within scripts by using the
ini_set() function.

• To connect to Oracle, some Oracle environment variables


need to be set before the web server starts.
Running PHP Scripts in a Browser
• PHP scripts are commonly run by loading them in
a browser:
http://localhost/myphpinfo.php
Running Scripts with Command Line 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.
Debugging PHP Scripts
• If not using a specialized PHP editor, debugging will
be an old-fashioned matter of using echo to print
variables and check code flow.

• The var_dump() function is useful for debugging


because 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 and
new lines coalescing, you will need to do:
END

You might also like