This document provides an overview of PHP features and installation including:
1) PHP is an interpreted scripting language that can be embedded into HTML and takes advantage of C code for performance. It provides common database features and functions.
2) PHP includes drivers for connecting to databases like Oracle, MySQL, PostgreSQL, SQLite, and others.
3) Installing PHP requires enabling extensions in php.ini and loading them in the proper order. PHP can be used for server-side web applications, command line scripts, or desktop applications.
20. Connection management try { $dbh = new PDO($dsn, $user, $pw); } catch (PDOException $e) { echo “connect failed:” . $e->getMessage(); } // use the database here // … // done; release the connection $dbh = null;
21.
22. Likely to be more resource efficient than PDO ‘pconnect’
23.
24. Let’s get data $dbh = new PDO($dsn); $stmt = $dbh->prepare( ‘ SELECT * FROM FOO’); $stmt->execute(); while ($row = $stmt->fetch()) { print_r($row); }
25.
26.
27. Let’s change data $deleted = $dbh->query( “ DELETE FROM FOO WHERE 1”); $changes = $dbh->query( “ UPDATE FOO SET active=1 ” . “WHERE NAME LIKE ‘%joe%’”);
28.
29. PDO offers a better way $stmt->prepare(‘INSERT INTO CREDITS (extension, name) VALUES (:extension, :name)’); $stmt->execute(array( ‘ :extension’ => ‘xdebug’, ‘ :name’ => ‘Derick Rethans’ ));
37. General Installation Considerations * Websites and web applications (server-side scripting) * Command line scripting * Desktop (GUI) applications For the first and most common form, you need three things: PHP itself, a web server and a web browser. You probably already have a web browser, and depending on your operating system setup, you may also have a web server (e.g. Apache on Linux and MacOS X; IIS on Windows). You may also rent webspace at a company. This way, you don't need to set up anything on your own, only write your PHP scripts, upload it to the server you rent, and see the results in your browser. In case of setting up the server and PHP on your own, you have two choices for the method of connecting PHP to the server. For many servers PHP has a direct module interface (also called SAPI). These servers include Apache, Microsoft Internet Information Server, Netscape and iPlanet servers. Many other servers have support for ISAPI, the Microsoft module interface (OmniHTTPd for example). If PHP has no module support for your web server, you can always use it as a CGI or FastCGI processor. This means you set up your server to use the CGI executable of PHP to process all PHP file requests on the server. If you are also interested to use PHP for command line scripting (e.g. write scripts autogenerating some images for you offline, or processing text files depending on some arguments you pass to them), you always need the command line executable.
38. ) PHP Sample Code Example PHP Script [ php_samples/anonymous_function.php ] Array ( [0] => ab [1] => stuv [2] => abcdef [3] => defghijkl ) [ php_samples/anonymous_function2.php ] Array ( [0] => ab [1] => stuv [2] => abcdef [3] => defghijkl ) [ php_samples/assignment1.php ] ( 5, 3 ) ( 11, 3 ) ( 17, 6 ) [ php_samples/block.php ] [ php_samples/class_extends.php ] [ php_samples/class_sample.php ] Programmer Name: Paul Conrad Paul Conrad has 12 years of programming experience. C++ is Paul Conrad's favorite programming language. Paul Conrad holds the degree: Bachelor of Science in Computer Science Programmer Name: Paul Conrad Paul Conrad has 22 years of programming experience. C++ is Paul Conrad's favorite programming language. Paul Conrad holds the degree: Bachelor of Science in Computer Science
39. [ php_samples/comment_sample.php ] Guess what? y is less than 5! [ php_samples/constant_sample.php ] Our school is California State University at San Bernardino Our school's Computer Science Dept has 4 academic programs php_samples/const_in_class.php ] [ php_samples/define1.php ] [ php_samples/define2.php ] [ php_samples/define3.php ]
beginTransaction() will raise an exception if not supported, regardless of your error mode rollBack is called when the handle is destroyed, to maintain consistency