1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP Developer''''s Dictionary- P13 pps

5 267 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 392,44 KB

Nội dung

PHP Developer’s Dictionary IT-SC book 60 city char (50), state char (2), zip char (10), phone char (25), fax char (25), email char (50), resume oid, primary key (cid)); This script creates a contacts table with the usual information and another item called resume that is of type oid. To enter data in this table, including the resume field, the insert query looks like this: INSERT INTO contacts VALUES (NEXTVAL('c'),'Test Name','Test Address', 'Test City', 'TS','11111','111.222.3333','444.555.6666','me@email.com', lo_import('/resumes/rcox.doc')); This query takes a file named rcox.doc from the /resumes directory and imports it into the database as a large object. Similarly, a select query to pull the resume out of the database looks like this: SELECT cid, name, address, city, state, zip, phone, fax, email, lo_export(resume,'/resumes/rcox.doc') FROM contacts WHERE cid=101; This exports the resume from the database, places it in the /resumes directory, and names the file rcox.doc. The following example illustrates how to use the PHP large object functionality to insert a large object into the database: <html> <head> <title>Large Objects</title> </head> <body> <? // Connect to the Postgres Database $conn = pg_Connect("localhost", "5432", "", "", "test"); if (!$conn) { echo "An database connection error occurred.\ n"; exit;} // Begin the Transaction $result = pg_exec($conn, "begin;"); if (!$result) { echo "An error occurred beginning the transaction.\ n"; exit;} // Lock the table $oid = pg_locreate($conn); echo ("The Large Object is created with Object ID = $oid<br>"); $handle = pg_loopen ($conn, $oid, "w"); echo ("The Large Object is opened in Write mode with Handle = $handle<br>"); PHP Developer’s Dictionary IT-SC book 61 pg_lowrite ($handle, "/resumes/rcox.doc"); pg_loclose ($handle); pg_exec ($conn, "INSERT INTO contacts VALUES (NEXTVAL('c'),'Test Name', 'Test Address','Test City','TS','11111','111.222.3333', '444.555.6666','me@email.com', $oid);"); pg_exec ($conn, "commit;"); pg_exec ($conn, "end;"); // Free the result pg_FreeResult($result); // Close the connection pg_Close($conn); ?> </body> </html> The output of this script should look something like this: The Large Object is created with Object ID = 24097 The Large Object is opened in Write mode with Handle = Resource id #3 The ordinary Web programmer would not use large objects on a regular basis. Instead of directly storing binaries in the database, it is usually preferable to store the link to the file and allow the binary to reside on the operating system's filesystem. Storing only the link allows the database to stay lean, and when the information is served to the Web browser, the Web server can include the path to the binary on the filesystem. PHP Developer’s Dictionary IT-SC book 62 Chapter 4. The Core PHP 4 Language Part of understanding a programming language is comprehending its semantics and syntax, and one of the most important parts of any language to digest is its core language elements. Core elements are syntax or concepts that you generally see across multiple languages. These can be anything from how to specify comments to how to control looping. In this chapter, we take a look at these elements as they pertain to the PHP language. We dive into the following topics: • Basic syntax • Constants • Control structures • Escape characters • Objects and functions • Operators • Predefined variables Basic Syntax Basic syntax is syntax that covers the three most basic elements of the PHP language. These include the tag that signifies PHP code and the two types of comments. Tags Tags refer to PHP identifier tags, which, in a sense, are much like HTML tags that direct the interpreter's actions. In this section, we document those tags and how they work with the language. <? ?> Syntax <? code ?> Description The <? ?> identifier represents the beginning and ending tags used to identify PHP code, and are shorthand for the <?php ?> method. The PHP parser will look for PHP Developer’s Dictionary IT-SC book 63 instances of this identifier so that it can execute the code within it. Also check out the entries of <?php ?> , <script language="php"> </script> , and <% %> for additional methods of signifying PHP code. <?php ?> Syntax <?php code ?> Description The <?php ?> identifier, which is the default, represents the beginning and ending tags used to identify PHP code. The PHP parser will look for instances of this identifier so that it can execute the code within it. Also check out the entries of <? ?> , <script language="php"> </script> , and <% %> for additional methods of signifying PHP code. <?php_track_vars?> Syntax <?php_track_vars?> Description The <?php_track_vars?> execution directive was used in versions of PHP prior to 4.0.1, but was officially removed in that version. Although it was included in PHP 4.0, it did not function, so it is safe to say that it has not been used at all in PHP 4. <?php_track_vars?> was simply a directive that told the engine to track certain variables while interpreting. If you want to obtain more information about this directive, please see the PHP Web site at http://www.php.net . <% %> Syntax <% code %> Description PHP Developer’s Dictionary IT-SC book 64 The <% %> identifier represents the beginning and ending tags used to identify PHP code when asp_tags=1 in the PHP configuration file. This is used to help developers who have worked previously with Microsoft's Active Server Pages (ASP) ease into the PHP language. Several applications, such as earlier versions of Macromedia's Dreamweaver, understand ASP tags and know that they should leave them alone, but do not understand the PHP tags. For these tags, the PHP parser will look for instances of this identifier so that it can execute the code within it. Also check out the entries of <? ?> , <?php ?> , and <script language="php"> </script> for additional methods of signifying PHP code. <script language= " php " > </script> Syntax <script language="php"> code </script> Description The <script language="php"> </script> identifier represents the beginning and ending tags used to identify PHP code. The PHP parser will look for instances of this identifier so that it can execute the code within it. Also check out the entries of <? ?> , <?php ?> , and <% %> for additional methods of signifying PHP code. Comments If you have been in the programming world at all, you are aware of the need for comments in your code. As in any other language, PHP provides several methods of signifying comments, which are disregarded by the interpreting engine. Comments are covered in this section of the chapter. // Syntax // comment Description The // PHP element, which is commonly referred to as a "one-line comment," enables programmers to include comments in their code. This particular style is the same as seen in other languages such as C, C++, Java, and JavaScript; comment . entries of < ?php ?> , <script language=" ;php& quot;> </script> , and <% %> for additional methods of signifying PHP code. < ?php ?> Syntax < ?php code ?>. language=" ;php& quot;> </script> , and <% %> for additional methods of signifying PHP code. < ?php_ track_vars?> Syntax < ?php_ track_vars?> Description The < ?php_ track_vars?> . represents the beginning and ending tags used to identify PHP code, and are shorthand for the < ?php ?> method. The PHP parser will look for PHP Developer’s Dictionary IT-SC book 63 instances

Ngày đăng: 07/07/2014, 05:20

TỪ KHÓA LIÊN QUAN