PHP concise function summary _ PHP Tutorial

Source: Internet
Author: User
Tags php book
Summary of simple PHP functions. PHP concise function topic: species PHP concise function brief: PHP simple clear function syntax suitable for the crowd: interested in open source communities, interested in php, a little time to understand php remarks: PHP concise function
Topic: Simple PHP functions
Brief introduction: PHP is simple and clear function syntax
Suitable for: interested in open-source communities, php, and a little time to learn about php
Note: I hope you can still give bricks.
1. related to mysql
Mysql_connect
Establish a connection with the MySQL server
Syntax

The code is as follows:


Resource mysql_connect (string server [, string usingname [, string password [, bool new_link [, int client_flags])
Eg:
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_data_seek


Move the internal query pointer to the query row
Syntax

The code is as follows:


Bool mysql_data_seek (resource result_indetifier, int row_number)
Eg:
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );
$ Res = mysql_query ("SELECT * from product ");
$ Row = mysql_fetch_array ($ res );
For ($ I = 0; $ I <$ num; $ I ++)
$ Row = mysql_fetch_array ($ res );
Mysql_data_seek ($ res, 0); // move the pointer back to the first row of the query result
Mysql_fetch_array


Store the query results in an array (one record for each array element)
Syntax

The code is as follows:


Array mysql_fetch_array (resource result [, int result_type])
Eg
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );
$ Res = mysql_query ("SELECT * from product ");
$ Row = mysql_fetch_array ($ res );
Mysql_fetch_object
A row of query results is obtained and stored as an object. the usage of MySQL_fetch_array () is the same. The difference is that mysql_fetch_object () can only obtain query results by field name.
Echo $ row-> fieldname; // correct usage
Echo $ row-> 0; // Incorrect usage


Syntax

The code is as follows:


Object mysql_fetch_object (resource result)
Eg
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );
$ Res = mysql_query ("SELECT * from product ");
$ Row = $ mysql_fetch_object ($ res );
While ($ row)
{
Echo $ row à p _ id;
Echo $ row à p _ name;
}
Mysql_insert_id


After adding a message using the INSERT command, you can use this function to obtain the unique id of the newly added record.
Syntax

The code is as follows:


Int mysql_insert_id ([esource link_identifier])
Eg
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );
$ SQLStr "insert into produce (p_id, p_name) VALUES ('', 'php book ')";
$ Res = mysql_query ($ res );
$ P_id = mysql_insert_id ();
Mysql_num_rows


There are several rows in the query result.
Syntax

The code is as follows:


Int mysql_num_rows (resource result)
Eg
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );
$ Res = mysql_query ("SELECT * from product ");
$ Num = mysql_num_rows ($ res );
Mysql_query


Send a query statement of SQL syntax
Syntax

The code is as follows:


Resource mysql_query (string query [, resource link_identifier])
Eg
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );
$ Res = mysql_query ("SELECT * from product ");
Mysql_select_db


Select the name of the database to be accessed
Syntax

The code is as follows:


Bool mysql_select_db (string database_name [, resource link_identifier])
Eg
$ DB_HOST = "localhost ";
$ DB_LOGIN = "root ";
$ DB_PASSWORD = "123456 ";
$ DB_NAME = "flag ";
$ Conn = mysql_connect ($ DB_HOST, $ DB_LOGIN, $ DB_PASSWORD );
Mysql_select_db ($ DB_NAME );


2. file system functions
Copy
Copy text
Syntax
Bool copy (string source, string dest)
Eg
Copy(“abc.txt ","/tmp/newabc.txt ");
Fclose
Close a pointer to open a file
Syntax
Bool fclose (resource handle)
Eg
$Fpw.fopen(“abc.txt "," w ");
Fclose ($ fp );
Fgets
Retrieve the column content from the position indicated by the file pointer
Syntax
String fgets (resource handle [, int length])
Eg
$Fpw.fopen(“abc.txt "," w ");
$ Txtdata = fgets ($ fp, 4096 );
File
Read the entire file content to the array
Syntax
Array file (string filename [, int use_include_path [, resource context])
Eg
$Content1_file(“abc.txt ");
File_exists
Check whether the file exists
Syntax
Bool file_exists (string filename)
Eg
If (file_exists(“abc.txt "))
Echo "this file exists ";
Else
Echo "this file does not exist ";
Filesize
Get file size
Syntax
Int filesize (string filename)
Eg
Inclusizeinclufilesize(“abc.txt ");
Fopen
Open a file or url
Syntax
Resource fopen (string filename, string mode [, bool use-include_path [, resource zcontext])
Eg
$Fp=fopen(“abc.txt ");
$ Fp = fopen ("http://www.jb51.net/bacteroid/", ”r ");
Fputs
Write data to a file
Syntax
Int fputs (resource handle, string [, int length])
Eg
$Fp=fopen(“abc.txt ");
Fputs ($ fp, "helloworld !");
Fseek
Set the position indicated by the file pointer
Syntax
Int fseek (resource handle, int offset [, int whence])
Eg
$Fpw.fopen(“abc.txt "," w ");
$ Txtdata = fgets ($ fp, 4096 );
Fseek ($ fp, 0); // point the pointer back to the starting position
Mkdir
Create a directory
Syntax
Bool mkdir (string pathname [, int mode [, bool recursive [, resource context])
Eg
Mkdir ("ljt/newfolder ");
Unlink
Delete an object
Syntax
Int unlink (string filename );
Eg
Unlink(cmdabc.txt ");
3. date and time functions
Data
Returns the local time/date in the specified format.
Syntax
String date (string format [, int timestamp])
Eg
$ Time = date ("Y-m-d g: I: s ");
Getdate
Obtain date and time information
Syntax
Array getdata ([int timestamp])
Eg
$ Now = getdate ();
$ Year = $ now ["year"];
$ Month = $ now ["month"];
Gettimeofday
Obtain the current time (including Greenwich Mean Time)
Syntax
Array gettimeofday (void)
Eg
$ Time = gettimeofday ();
4. string processing functions
Explode
Splits a string into an array based on the specified delimiter.
Syntax
Array explode (string separator, string [, int limit])
Eg
$ Str = "a, B, c ";
$ Res = explode (",", $ str); // $ res [0] =
Implode
Concatenates the array content into a string
Syntax
String implode (string glue, array pieces)
Eg
$ Newarray = array ('A', 'B', 'C ');
$ Res = implode (",", $ newarray); // $ res = a, B, c
Strlen
Returns the length of a string.
Syntax
Int strlen (string)
Eg
Strlen ("www.gxnu.edu.cn"); // returns 15
Substr
Obtains a specified part of the character string (sub-string)
Syntax
String substr ("www.gxnu.edu.cn",); // return "ww. gxnu"
5. mathematical function library
Ceil
Unconditionally carry the decimal part of the floating point number
Syntax
Float ceil (float value)
Eg
Echo ceil (9.99); // returns 10
Echo ceil (9.12); // returns 10
Cos
Returns the cosine of a floating point value.
Syntax
Float cos (float arg)
Eg
$ Numcos = cos (0.5 );
Floor
Remove the decimal part of the floating point number unconditionally.
Syntax
Float floor (floor value)
Eg
Echo floor (9.12); // return 9
Echo floor (9.99); // return 9
Rand
Generates a random value in a range.
Syntax
Int rand ([int min, in max])
Eg
$ Num = rand (0,100); // generates a random value between 1 and 100.
Round
Rounds the decimal part of a floating point number to carry.
Syntax
Float round (float value)
Eg
Float round (9.99) // returns 10
Float round (9.12) // return 9
Sin
Returns the sine of a floating point value.
Syntax
Float sin (float arg)
Eg
$ Numsin = sin (0.5 );
6. Session functions
Session_register
Description: variables in one or more sessions
Syntax
Bool session_register (mixed name [, mixed...])
Eg
$ Name = "flag ";
Session_register ("name ");
Session_start
Initialize Session information
Syntax
Bool session (void)
Eg
Session_start ();
7. array functions
Count
There are several array functions in the calculation array.
Syntax
Int count (mixed var [, int mode])
Eg
Count ($ array );
List
Assign the element values in the array to the variable.
Syntax
Void list (mixed varname, mixed ...)
Eg
$ Array = array (a, B, c );
List ($ str1, $ str2, $ str3) = $ array; // $ str1 =
Range
Creates an array within the specified range.
Syntax
Array range (int low, int high [, int step])
Eg
$ Array = array (0, 9 );
Shuffle
Re-random sorting of elements in the array
Syntax
Bool shuffle (array)
Eg
Shuffle ($ array );

Theme of remark: PHP concise function description: PHP simple and clear function syntax suitable for people: interested in open-source communities, interested in php, a little time to understand php remarks :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.