MySQL /PHP Database Applications Second Edition phần 9 doc

81 256 0
MySQL /PHP Database Applications Second Edition phần 9 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

mysql> grant all on guestbook.* to jim@localhost identified by “pword”; This command makes all the necessary changes to the user and db tables. The first part of the grant statement can take the argument all (which must be followed by WITH GRANT if it’s really to grant all privileges), or it can take any of the options listed in the user table. Most often you are granting rights to use SQL statements (select, create, alter, delete, drop, index, insert, and update). The second portion of the grant statement (on guestbook in the example) iden- tifies where privileges are to be applied: universally, to a single database, to tables, or to columns. Table E-1 shows how to indicate where privileges should be applied. TABLE E-1 SETTING PERMISSIONS Identifier Meaning grant all on *.* Rights are universal; inserted into the user table grant all on database.* Rights apply to all tables in a single database grant all on database.table_name Rights apply to a single table grant all(col1, col2) Rights apply only to specific columns in a on database.table_name specific database and table The third portion of the grant statement (to jim@localhost in the example) indicates the user to be given access. As we mentioned earlier, MySQL needs both a name and a host. In the grant statement these are separated by the @ symbol. Finally, the identified by portion of the grant statement gives the user a password. Here are a few more examples of grant statements: grant select, update, insert on guestbook2k.guestbook to alvin@localhost identified by “pword”; The preceding statement allows alvin to view, update, and insert records into the table guestbook in database guestbook2k. grant select, update (name, url) on guestbook2k.guestbook to chipmunk@localhost identified by “pword”; Appendix E: MySQL User Administration 603 With the preceding statement the user can view and update only two columns (name and url). No deletes or inserts are allowed. grant all on *.* to josh@localhost identified by “pword” WITH GRANT OPTION; The preceding statement gives this user all privileges, which means that josh@ localhost is even allowed to grant privileges to other users. The revoke statement If you want to remove some of a user’s privileges, you can use the revoke statement. To remove shutdown privileges from a user who had been granted all privileges, like josh in the preceding example, you can run the following: revoke Shutdown on *.* from josh@localhost; Notice that the word from is used in the revoke statement in place of to. Otherwise revoke works just like grant. To remove a user entirely you must run a delete statement against the user table. Because the user is identified by a name and a host, the following should do it: delete from user where user=’username’ and host=’hostname’ Viewing grants You can use the SHOW GRANTS statement to see the exact grants available at a given time. All you need to know is the username and host. mysql> show grants for jayg@localhost; + + | Grants for jayg@localhost | + + | GRANT ALL PRIVILEGES ON my_test.* TO ‘jayg’@’localhost’ | + + 1 row in set (0.00 sec) 604 Part V: Appendixes Reloading grants The grant tables are loaded into memory when the MySQL daemon is started. Changes made to the grant tables that do not make use of the grant command do not take effect until you tell MySQL to reload the grant tables. You can do this in the shell with the mysqladmin program: shell> mysqladmin flush-privileges or in the mysql client with the flush privileges command. Just run: flush privileges Appendix E: MySQL User Administration 605 Appendix F PHP Function Reference PHP CONTAINS MORE FUNCTIONS than could possibly be listed in this book. The follow- ing tables present many of the most commonly used functions available as of PHP version 4. To keep up on exactly what’s available in PHP, and to check out what new functions are available in PHP 5, make sure to check in with the online docu- mentation: http://www.php.net/docs.php. TABLE F-1 MYSQL FUNCTIONS Function Return Value Action mysql_connect([string hostname resource Opens a connection to a [:port][:/path/to/socket]] MySQL server [, string username] [, string password] [, bool new]) mysql_pconnect([string hostname resource Opens a persistent [:port][:/path/to/socket]] connection to a MySQL [, string username] [, string server password]) mysql_close([int link_identifier]) bool Closes a MySQL connection mysql_select_db(string bool Selects a MySQL database database_name [, int link_identifier]) mysql_get_client_info(void) string Returns a string that represents the client- library version mysql_get_host_info([int string Returns a string describing link_identifier]) the type of connection in use, including the server- host name Continued 607 TABLE F-1 MYSQL FUNCTIONS (Continued) Function Return Value Action mysql_get_proto_info int Returns the protocol ([int link_identifier]) version used by the current connection mysql_get_server_info string Returns a string that ([int link_identifier]) represents the server- version number mysql_create_db(string bool Creates a MySQL database database_name [, int link_identifier]) mysql_drop_db(string bool Drops (deletes) a MySQL database_name [, int database link_identifier]) mysql_query(string query resource Sends an SQL query to [, int link_identifier] MySQL [, int result_mode]) mysql_unbuffered_query(string resource Sends an SQL query to query [, int link_identifier] MySQL, without fetching [, int result_mode]) and buffering the result rows mysql_db_query(string resource Sends an SQL query to database_name, string query MySQL [, int link_identifier]) mysql_list_dbs([int resource Lists the databases link_identifier]) available on a MySQL server mysql_list_tables(string resource Lists the tables in a MySQL database_name [, int database link_identifier]) mysql_list_fields(string resource Lists the MySQL result database_name, string table_name fields [, int link_identifier]) mysql_error([int string Returns the text of the link_identifier]) error message from the previous MySQL operation 608 Part V: Appendixes Function Return Value Action mysql_errno([int int Returns the number of the link_identifier]) error message from the previous MySQL operation mysql_affected_rows([int int Gets the number of link_identifier]) affected rows in the previous MySQL operation mysql_escape_string(string string Escape string for a MySQL to_be_escaped) query mysql_insert_id([int int Gets the ID generated from link_identifier]) the previous INSERT operation mysql_result(int result, mixed Gets result data int row [, mixed field]) mysql_num_rows(int result) int Gets the number of rows in a result mysql_num_fields(int result) int Gets the number of fields in a result mysql_fetch_row(int result) array Gets a result row as an enumerated array mysql_fetch_object(int result object Fetches a result row as an [, int result_type]) object mysql_fetch_array(int result array Fetches a result row as an [, int result_type]) array (associative, numeric, or both) mysql_fetch_assoc(int result) array Fetches a result row as an associative array mysql_data_seek(int result, bool Moves the internal result int row_number) pointer mysql_fetch_lengths(int result) array Gets the maximum data size of each column in a result mysql_fetch_field(int result object Gets the column [, int field_offset]) information from a result and returns it as an object Continued Appendix F: PHP Function Reference 609 TABLE F-1 MYSQL FUNCTIONS (Continued) Function Return Value Action mysql_field_seek(int result, bool Sets the result pointer to a int field_offset) specific field offset mysql_field_name(int result, string Gets the name of the int field_index) specified field in a result mysql_field_table(int result, string Gets the name of the table int field_offset) the specified field is in mysql_field_len(int result, int Returns the length of the int field_offset) specified field mysql_field_type(int result, string Gets the type of the int field_offset) specified field in a result mysql_field_flags(int result, string Gets the flags associated int field_offset) with the specified field in a result mysql_free_result(int result) bool Frees memory associated with the result TABLE F-2 STRING-MANIPULATION FUNCTIONS Function Return Value Action bin2hex(string data) string Converts the binary repre- sentation of data to hex strspn(string str, string mask) int Finds the length of the initial segment consisting entirely of characters found in mask strcspn(string str, string mask) int Finds the length of the initial segment consisting entirely of characters not found in mask nl_langinfo(int item) string Queries the language and locale information 610 Part V: Appendixes Function Return Value Action strcoll(string str1, string str2) int Compares two strings using the current locale chop(string str string An alias for rtrim [, string character_mask]) rtrim(string str string Removes trailing white [, string character_mask]) space trim(string str string Strips white space from [, string character_mask]) the beginning and end of a string ltrim(string str string Strips white space from [, string character_mask]) the beginning of a string wordwrap(string str [, int width string Wraps a string to a given [, string break [, int cut]]]) number of characters using a string break character. explode(string separator, array Splits a string-on-the string str [, int limit]) string separator and returns an array of components join(array src, string glue) string An alias for implode implode(array src, string glue) string Joins array elements by placing the glue string between items and returns one string strtok([string str,] string Tokenizes a string string token) strtoupper(string str) string Makes a string upper case strtolower(string str) string Makes a string lower case basename(string path string Returns the file-name [, string suffix]) component of the path dirname(string path) string Returns the directory- name component of the path Continued Appendix F: PHP Function Reference 611 TABLE F-2 STRING-MANIPULATION FUNCTIONS (Continued) Function Return Value Action pathinfo(string path) array Returns information about a certain string stristr(string haystack, string Finds the first occurrence string needle) of a string within another (case-insensitive) strstr(string haystack, string Finds the first occurrence string needle) of a string within another strchr(string haystack, string An alias for strstr string needle) strpos(string haystack, int Finds the position of the string needle [, int offset]) first occurrence of a string within another strrpos(string haystack, int Finds the position of the string needle) last occurrence of a character in a string within another strrchr(string haystack, string Finds the last occurrence string needle) of a character in a string within another chunk_split(string str [, int string Returns a split line chunklen [, string ending]]) substr(string str, int start string Returns part of a string [, int length]) substr_replace(string str, string Replaces part of a string string repl, int start with another string [, int length]) quotemeta(string str) string Quotes meta-characters ord(string character) int Returns the ASCII value of a character chr(int ascii) string Converts ASCII code to a character ucfirst(string str) string Makes a string’s first character upper case 612 Part V: Appendixes [...]... set_socket_blocking(resource socket, int mode) bool Sets blocking/non-blocking mode on a socket socket_set_timeout(int socket_descriptor, int seconds, int microseconds) bool Sets timeout on socket read to seconds plus socket_get_status(resource socket_descriptor) array microseconds Returns an array describing socket status Continued 623 624 Part V: Appendixes TABLE F-8 FUNCTIONS FOR WORKING WITH FILES (Continued)... Returns true if var is callable Return Value Action TABLE F- 19 SESSION FUNCTIONS Function session_set_cookie_params(int void lifetime [, string path [, string domain [, bool secure]]]) session_get_cookie_params(void) array Sets the session-cookie parameters Returns the session-cookie parameters Continued 635 636 Part V: Appendixes TABLE F- 19 SESSION FUNCTIONS (Continued) Function Return Value Action... xml_set_end_namespace_decl_ handler(int pind, string hdl) int Sets up a character-data handler xml_parse(int pind, string data [, int isFinal]) int Starts parsing an XML document xml_parse_into_struct(int pind, string data, array &struct, array &index) int Parsing a XML document xml_get_error_code(int pind) int Gets XML parser-error code xml_error_string(int code) string Gets XML parser-error string xml_get_current_line_number... mode touch(string filename [, int time [, int atime]]) bool Sets the modification time for the file clearstatcache(void) void Clears the file’s stat cache Continued 625 626 Part V: Appendixes TABLE F -9 FILE STATUS FUNCTIONS (Continued) Function Return Value Action fileperms(string filename) int Gets file permissions fileinode(string filename) int Gets the file inode filesize(string filename) int Gets... the hyperbolic cosine of the number, defined as (exp(number) + exp(–number))/2 tanh(float number) float Returns the hyperbolic tangent of the number, defined as sinh(number)/ cosh(number) Continued 6 29 630 Part V: Appendixes TABLE F-14 MATH FUNCTIONS (Continued) Function Return Value Action asinh(float number) float Returns the inverse hyperbolic sine of the number, that is, the value whose hyperbolic... arrays array_key_exists(mixed key, array search) bool Checks if the given key or index exists in the array array_chunk(array input, int size [, bool preserve_keys]) array Splits the array into chunks 6 19 620 Part V: Appendixes TABLE F-4 DATE/TIME FUNCTIONS Function Return Value Action time(void) int Returns the current Unix timestamp Mktime(int hour, int min, int sec, int mon, int day, int year) int... Binary-safe file read fgetcsv(resource fp, int length [, string delimiter]) array Gets a line from the file pointer and parses it for CSV fields realpath(string path) string Returns the resolved path TABLE F -9 FILE STATUS FUNCTIONS Function Return Value Action disk_total_space(string path) float Gets total disk space for the file system that path is on disk_free_space(string path) float Gets free disk space . server- version number mysql_ create_db(string bool Creates a MySQL database database_name [, int link_identifier]) mysql_ drop_db(string bool Drops (deletes) a MySQL database_ name [, int database link_identifier]) mysql_ query(string. server password]) mysql_ close([int link_identifier]) bool Closes a MySQL connection mysql_ select_db(string bool Selects a MySQL database database_name [, int link_identifier]) mysql_ get_client_info(void) string. resource Lists the databases link_identifier]) available on a MySQL server mysql_ list_tables(string resource Lists the tables in a MySQL database_ name [, int database link_identifier]) mysql_ list_fields(string

Ngày đăng: 12/08/2014, 21:20

Mục lục

  • Part V Appendixes

    • Appendix F

    • Appendix G

    • Appendix H

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

  • Đang cập nhật ...

Tài liệu liên quan