Beginning PHP6, Apache, MySQL Web Development- P25 doc

30 264 0
Beginning PHP6, Apache, MySQL Web Development- P25 doc

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Appendix C: PHP6 Functions 751 Miscellaneous Functions Function signatures marked with a * are not available when running on Windows. Function Description void __halt_compiler(void) Halt the execution of the PHP compiler. int connection_aborted(void) Return whether the client connection has been aborted. int connection_status(void) Return the connection status. mixed constant(string $name) Return the value of a constant. bool define(string $name, mixed $value[, bool $case_insensitive]) Define a constant. bool defined(string $name) Return whether a constant exists. void die([mixed $status]) Alias for exit() . mixed eval(string $string) Evaluate a string as PHP code. void exit([mixed $status]) Terminate execution of the script. mixed get_browser([string $user_ agent[, bool $return_array]) Return an object with information about a browser. Information will be returned as an array if $return_array is true. Relies on browscap.ini . mixed highlight_file(string $filename[, bool $return]) Output the syntax - highlighted source PHP file. The source will be returned as a string instead if $return is true. mixed highlight_string(string $string[, bool $return]) Output a syntax - highlighted string of PHP code. The string will be returned instead if $return is true. int ignore_user_abort([bool $value]) Set whether a script should continue executing after the user aborts the connection. string php_strip_ whitespace(string $filename) Return the source code of a file with comments and whitespace removed. mixed show_source(string $filename) Alias for highlight_file() . int sleep(int $seconds) Pause execution of the script for a specified number of seconds. bapp03.indd 751bapp03.indd 751 12/10/08 5:34:05 PM12/10/08 5:34:05 PM Appendix C: PHP6 Functions 752 Function Description array sys_getloadavg(void) * Return an array with the system ’ s load averages over the last 1, 5, and 15 minutes. mixed time_nanosleep(int $seconds, int $nanoseconds) * Pause execution of the script for a specified number of seconds and nanoseconds. bool time_sleep_until(float $timestamp) * Pause execution of the script until a specified time. string uniqid($prefix[, bool $entropy]) Return a unique ID based on the current time and named prefix. void usleep(int $microseconds) Pause execution of the script for a specified number of microseconds. bapp03.indd 752bapp03.indd 752 12/10/08 5:34:06 PM12/10/08 5:34:06 PM D MySQL Data Types This appendix contains a listing of data types that are available in MySQL. Visit http:// dev.mysql.com/doc/refman/5.1/en/data - type - overview.html for a complete discussion on each data type. Numeric Data Types MySQL Field Type Description BIGINT[(m)] [UNSIGNED] Numeric field that stores integers from Ϫ 9,223,372, 036,854,775,808 to 9,223,372,036,854,775,807. m represents the maximum display width. Adding the UNSIGNED parameter allows storage of 0 to 18,446,744,073,709,551,615. BIT[(m)] Bit - type field. m represents the optional number of bits per value. BOOL, BOOLEAN Synonym for TINYINT(1) . A value of 0 represents false, and nonzero values represent true. DEC Synonym for DECIMAL . DECIMAL[(m[,d])] [UNSIGNED] A fixed - point numeric field that can store decimals. m represents the total number of displayed digits. d represents how many digits follow the decimal point. UNSIGNED allows only positive numbers to be stored. bapp04.indd 753bapp04.indd 753 12/10/08 5:33:08 PM12/10/08 5:33:08 PM Appendix D: MySQL Data Types 754 MySQL Field Type Description DOUBLE[(m,d)] [UNSIGNED] A double - precision floating - point number that stores values from Ϫ 1.7976931348623157E+308 to Ϫ 2.2250738585072014E Ϫ 308, 0, and 2.2250738585072014E Ϫ 308 to 1.7976931348623157E+308. m represents the total number of displayed digits. d represents how many digits follow the decimal point. UNSIGNED allows only positive numbers to be stored. DOUBLE PRECISION[(m,d)] [UNSIGNED] Synonym for DOUBLE . FIXED Synonym for DECIMAL . FLOAT[(m,d)] [UNSIGNED] A single - precision floating - point number that stores values from Ϫ 3.402823466E+38 to Ϫ 1.175494351E Ϫ 38, 0, and 1.175494351E Ϫ 38 to 3.402823466E+38. m represents the total number of displayed digits. d represents how many digits follow the decimal point. UNSIGNED allows only positive numbers to be stored. INT[(m)] [UNSIGNED] Numeric field that stores integers from Ϫ 2,147,483,648 to 2,147,483,647. m represents the maximum display width. Adding the UNSIGNED parameter allows storage of 0 to 4,294,967,295. INTEGER[(m)] [UNSIGNED] Synonym for INT . MEDIUMINT[(m)] [UNSIGNED] Numeric field that stores integers from Ϫ 8,388,608 to 8,388,607. m represents the maximum display width. Adding the UNSIGNED parameter allows storage of 0 to 16,777,215. NUMERIC Synonym for DECIMAL . SMALLINT[(m)] [UNSIGNED] Numeric field that stores integers from Ϫ 32,768 to 32,767. m represents the maximum display width. Adding the UNSIGNED parameter allows storage of 0 to 65,535. REAL[(m,d)] [UNSIGNED] Synonym for DOUBLE . (Note: If REAL_AS_FLOAT mode is enabled, then REAL is a synonym for FLOAT .) TINYINT[(m)] [UNSIGNED] Numeric field that stores integers from Ϫ 128 to 127. m represents the maximum display width. Adding the UNSIGNED parameter allows storage of 0 to 255. bapp04.indd 754bapp04.indd 754 12/10/08 5:33:08 PM12/10/08 5:33:08 PM Appendix D: MySQL Data Types 755 Date and Time Data Types MySQL Field Type Description DATE Stores a date as YYYY - MM - DD from 1000 - 01 - 01 to 9999 - 12 - 31. DATETIME Stores both a date and time as YYYY - MM - DD HH:MM:SS from 1000 - 01 - 01 00:00:00 to 9999 - 12 - 31 23:59:59. TIMESTAMP Stores a UNIX Epoch timestamp as YYYY - MM - DD HH:MM:SS from 1970 - 01 - 01 00:00:01 to 2038 - 01 - 09 03:14:07. TIME Stores a time as HH:MM:SS from Ϫ 838:59:59 to 838:59:59. YEAR[(2|4)] Stores a year as either YY or YYYY , depending on whether two - or four - digit format is specified (default is four - digit). The range is from 1901 to 2155 in four - digit format, and from 70 to 69, representing years from 1970 to 2069, in two - digit format. String Data Types MySQL Field Type Description BINARY[(m)] Stores fixed - length binary byte strings. m represents the length in bits. BLOB[(m)] Stores binary byte strings. m represents the length in bytes from 0 to 65,535. [NATIONAL] CHAR[(m)] Synonym for CHARACTER . CHAR BYTE[(m)] Synonym for BINARY . [NATIONAL] CHARACTER[(m)] Stores a fixed - length character string that is right - padded with spaces. m represents the length in characters from 0 to 255. [NATIONAL] CHARACTER VARYING[(m)] Stores a variable - length character string. m represents the length in characters from 0 to 65,535. ENUM( ‘ value1 ’ , ‘ value2 ’ , ) Stores a string value. Allows only specified values to be stored in the field (up to a maximum of 65,535 different values). LONGBLOB Stores binary byte strings. m represents the length in bytes from 0 to 4,294,967,295 (4GB). bapp04.indd 755bapp04.indd 755 12/10/08 5:33:09 PM12/10/08 5:33:09 PM Appendix D: MySQL Data Types 756 MySQL Field Type Description LONGTEXT Stores a variable - length character string. m represents the length in characters from 0 to 4,294,967,295 (4GB). MEDIUMBLOB Stores binary byte strings. m represents the length in bytes from 0 to 16,777,215. MEDIUMTEXT Stores a variable - length character string. m represents the length in characters from 0 to 16,777,215. NCHAR[(m)] Synonym for NATIONAL CHARACTER . NVCHAR[(m)] Synonym for NATIONAL CHARACTER VARYING . SET( ‘ value1 ’ , ‘ value2 ’ , ) Stores a set of string values from the specified list values (up to a maximum of 64 members). TEXT[(m)] Stores a variable - length character string. m represents the length in characters from 0 to 65,535. TINYBLOB Stores binary byte strings. m represents the length in bytes from 0 to 255. TINYTEXT Stores a variable - length character string. m represents the length in characters from 0 to 255. VARBINARY[(m)] Stores variable - length binary byte strings. m represents the length in bits. [NATIONAL] VARCHAR[(m)] Synonym for CHARACTER VARYING . Spatial Data Formats Spatial data is beyond the scope of this book. See http://dev.mysql.com/doc/refman/5.1/en/ supported - spatial - data - formats.html for more information on the standard spatial formats used by MySQL. bapp04.indd 756bapp04.indd 756 12/10/08 5:33:09 PM12/10/08 5:33:09 PM E My SQL Quick Reference This appendix lists some quick reference notes for your use. These topics are covered in more depth in Chapter 3 and on the MySQL web site at www.mysql.com . Database Manipulation Commands Use the following commands to create and make changes to your database and tables. Command What It Does CREATE DATABASE [IF NOT EXISTS] db_name Creates a database CREATE TABLE [IF NOT EXISTS] tbl_ name (col1 col_type, col2 col_ type, ) Creates a table ALTER TABLE tbl_name ADD col col_ type [AFTER col], Adds a new column to a table in the database ALTER TABLE tbl_name MODIFY col new_col_type, Changes columns ’ type definitions ALTER TABLE tbl_name CHANGE old_ col new_col new_col_type, Changes columns ’ names and type definitions ALTER TABLE tbl_name DROP col, Removes columns from a table in the database RENAME TABLE old_tbl_name TO new_ tbl_name Renames a table in the database bapp05.indd 757bapp05.indd 757 12/10/08 5:31:50 PM12/10/08 5:31:50 PM 758 Appendix E: My SQL Quick Reference Retrieving Data from the Database You can access the data stored in your tables with the following statement: SELECT col1[, col2, . . .] FROM tbl_name [WHERE condition] [ORDER BY col [ASC|DESC]] [LIMIT offset, num_rows] You can use * to retrieve all columns in a table: SELECT * FROM tbl_name Condition Clauses Use the following conditions in conjunction with the SELECT statement: col = value col > value col < value col > = value col < = value col != value col < > value col BETWEEN value1 AND value2 col NOT BETWEEN value1 AND value2 col LIKE value col NOT LIKE value col IS NULL col IS NOT NULL col IN (value1, value2, value3, . . .) col NOT IN (value1, value2, value3, . . .) Command What It Does INSERT [IGNORE] INTO tbl_name [(col1, col2, … )] VALUES (value1, value2, ) Inserts a row into a table UPDATE [IGNORE] tbl_name SET col1=value1, col2=value2, WHERE condition [ORDER BY ] [LIMIT count] Modifies information already stored in the table DELETE [IGNORE] FROM tbl_name WHERE condition [ORDER BY ] [LIMIT count] Deletes information from the table TRUNCATE TABLE tbl_name Deletes all information from the table DROP TABLE [IF EXISTS] tbl_name Deletes a table from the database DROP DATABASE [IF EXISTS] db_name Deletes a database bapp05.indd 758bapp05.indd 758 12/10/08 5:31:50 PM12/10/08 5:31:50 PM 759 Appendix E: My SQL Quick Reference MySQL supports wildcard matching. Use to match a single character. Use % to match zero or more characters. Selecting from Multiple Tables You can retrieve information from two or more tables at once by using JOIN s. MySQL supports the following syntax variations: SELECT table1.col1, table1.col2, table2.col1, table2.col2 FROM table1, table2 WHERE table1.col1 = table2.col1 or SELECT table1.col1, table1.col2, table2.col1, table2.col2 FROM table1 JOIN table2 ON table1.col1 = table2.col1 Sorting the Results You can sort the results of the SELECT query by using the ORDER BY clause (and the optional ascending or descending qualifier): SELECT * FROM table WHERE col1 = value1 ORDER BY col2 [ASC|DESC] Limiting the Results If you would like to limit the results returned from your query, you can do so with a LIMIT clause: SELECT * FROM table WHERE col1 = value1 LIMIT [offset,] row_count bapp05.indd 759bapp05.indd 759 12/10/08 5:31:51 PM12/10/08 5:31:51 PM bapp05.indd 760bapp05.indd 760 12/10/08 5:31:51 PM12/10/08 5:31:51 PM [...]... database that holds all the data to be accessed by your web site Follow these steps to install it: 1 If there isn’t a user on the system dedicated to running the mysql daemon (typically mysql) , you’ll need to create one To do this, enter the following commands in a console: groupadd mysql useradd -r -g mysql mysql 2 Go to the MySQL web site at www .mysql. com, and click the Developer Zone tab Then, click... Run the mysql_ install_db script with elevated privileges to install the initial database: sudo scripts /mysql_ install_db 12 Set the permissions on the installed files: sudo chown -R root /usr/local /mysql sudo chown -R mysql /usr/local /mysql/ var sudo chgrp -R mysql /usr/local /mysql 778 bapp09.indd 778 12/10/08 5:27:35 PM Appendix I: Installation and Configuration on Linux 13 It is advised to run MySQL with... component’s web site if you want more detailed installation instructions or information on other supported platforms ❑ ❑ MySQL: http://dev .mysql. com /doc/ refman/5.1/en/installing-source.html ❑ bapp09.indd 777 Apache: http://httpd.apache.org/docs/2.2/install.html PHP: http://www.php.net/manual/en/install.unix.php 12/10/08 5:27:34 PM Appendix I: Installation and Configuration on Linux Install MySQL MySQL is... Start the MySQL daemon: sudo mysqld_safe user =mysql & You’ll probably want to add the previous command to whatever facilities are available to automatically start the daemon at boot This varies by OS, so you’ll need to find out what works on your system Here is one easy way to add this that works with most systems (but may not be the best way): sudo echo ‘/usr/local /mysql/ bin/mysqld_safe user =mysql &’... and has shipped in the default build of PHP starting with version 5.1 Of course, you’ll be all set on this front if you’re using version 6 (which we assume you are, since you’re reading Beginning PHP6, Apache, MySQL Web Development) Linux users shouldn’t have to do anything out of the ordinary for PDO to be available, and Windows users just need to uncomment the extension=php_pdo.dll line in their php.ini,... the easiest way to accomplish it: mysql: host=localhost;dbname=mywebapp This DSN is used to establish a connection to a MySQL server running on the localhost, and you are connecting to a database named test You pass the DSN, username, and password to the PDO constructor when you create a new instance of the object, like this: $db = new PDO( mysql: host=localhost;dbname=mywebapp’, ‘dbuser’, ‘dbpassword’);... www.ipowerweb.com ❑ www.midphase.com ❑ www.infinology.com ❑ www.powweb.com ❑ www.invision.net ❑ www.ait.com ❑ www.1and1.com ❑ www.websitesource.com 768 bapp07.indd 768 12/10/08 5:29:03 PM H An Introduction to PHP Data Objects PHP is a terrific programming language It is relatively easy to learn, especially if you are already familiar with other programming languages You can build some excellent interactive web. .. support-files/my-medium.cnf /etc/my.cnf MySQL looks in /etc/my.cnf for global configuration options Any changes you wish to make to customize MySQL s configuration should be made in this file You can also place a my.cnf file in the server ’s data directory (/usr/local /mysql/ var in our setup) to supply serverspecific configuration options, if you plan on having multiple instances running 14 Add MySQL s bin directory... the tarball, and change to the directory it creates: tar -vxzf mysql- 5.0.51b.tar.gz cd mysql- 5.0.51b 8 Next, configure the source: /configure prefix=/usr/local /mysql Using the prefix switch tells the installer where to put the MySQL libraries and binaries after they’re built We recommend placing them in /usr/local /mysql, but you may choose to specify a different value, depending on your needs or your... (username, first_name, last_name, email) VALUES (“’ mysql_ real_escape_string($username, $db) ‘”, (“’ mysql_ real_escape_string($first_name, $db) ‘”, (“’ mysql_ real_escape_string($last_name, $db) ‘”, (“’ mysql_ real_escape_string($email, $db) ‘”)’; $result = mysql_ query($query, $db); A PDOStatement is an interesting object, in that at first it represents a prepared statement After you execute that statement, . 12/10/08 5:34:06 PM12/10/08 5:34:06 PM D MySQL Data Types This appendix contains a listing of data types that are available in MySQL. Visit http:// dev .mysql. com /doc/ refman/5.1/en/data - type - overview.html . of this book. See http://dev .mysql. com /doc/ refman/5.1/en/ supported - spatial - data - formats.html for more information on the standard spatial formats used by MySQL. bapp04.indd 756bapp04.indd. notes for your use. These topics are covered in more depth in Chapter 3 and on the MySQL web site at www .mysql. com . Database Manipulation Commands Use the following commands to create

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

Mục lục

  • cover.pdf

  • page_c1.pdf

  • page_r01.pdf

  • page_r02.pdf

  • page_r03.pdf

  • page_r04.pdf

  • page_r05.pdf

  • page_r06.pdf

  • page_r07.pdf

  • page_r08.pdf

  • page_r09.pdf

  • page_r10.pdf

  • page_r11.pdf

  • page_r12.pdf

  • page_r13.pdf

  • page_r14.pdf

  • page_r15.pdf

  • page_r16.pdf

  • page_r17.pdf

  • page_r18.pdf

Tài liệu cùng người dùng

Tài liệu liên quan