PHP Concise functions
Topic: Class-like bacteria PHP concise function
Summary: PHP simple and straightforward function syntax
Suitable for people: interested in the open source community, interested in PHP, have a little time to understand PHP
Remark: Hope everybody throws bricks, still egg, hehe
1. Related to MySQL
Mysql_connect
Establish a connection to the MySQL server
Grammar
Copy CodeThe 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 over the query line
Grammar
Copy CodeThe 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 line of the query fruit
Mysql_fetch_array
The result of the query exists in the array (one record per array element)
Grammar
Copy CodeThe 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
Gets a row of query results, stored as Object type, exactly the same as mysql_fetch_array (), except that mysql_fetch_object () can only get query results by field names
Echo $row->fieldname; Correct usage
Echo $row->0; Error usage
Grammar
Copy CodeThe 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 get the unique ID of the record you just added
Grammar
Copy CodeThe 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 a few lines in the result of getting the query
Grammar
Copy CodeThe 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
A query statement that sends out a SQL syntax
Grammar
Copy CodeThe 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 you want to access
Grammar
Copy CodeThe 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
Grammar
BOOL Copy (string source,string dest)
eg
Copy ("Abc.txt", "/tmp/newabc.txt");
Fclose
Close a pointer to an open file
Grammar
BOOL Fclose (Resource handle)
eg
$FP =fopen ("Abc.txt", "w");
Fclose ($FP);
Fgets
Gets the contents of the column from the location indicated by the file pointer
Grammar
String fgets (Resource handle[,int length])
eg
$FP =fopen ("Abc.txt", "w");
$txtdata = Fgets ($fp, 4096);
File
Reads the entire file contents into the array
Grammar
Array file (string Filename[,int use_include_path[,resource context])
eg
$content =file ("Abc.txt");
File_exists
Check if the file exists
Grammar
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
Grammar
int filesize (string filename)
eg
$size =filesize ("Abc.txt");
fopen
Open a file or URL
Grammar
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
Grammar
int fputs (Resource handle,string string[,int length])
eg
$FP =fopen ("Abc.txt");
Fputs ($fp, "helloworld!");
Fseek
Sets the location that the file pointer refers to
Grammar
int fseek (Resource handle,int offset[,int whence])
eg
$FP =fopen ("Abc.txt", "w");
$txtdata =fgets ($fp, 4096);
Fseek ($fp, 0);//Pointing the pointer back at the beginning
Mkdir
Create a Directory
Grammar
BOOL MkDir (String Pathname[,int mode[,bool Recursive[,resource Context]])
eg
mkdir ("Ljt/newfolder");
Unlink
deleting files
Grammar
int unlink (string filename);
eg
Unlink ("Abc.txt");
3. Date and Time function
Data
Returns the local time/date in the specified format
Grammar
String Date (string format[,int timestamp])
eg
$time =date ("y-m-d g:i:s");
GetDate
Get information about dates and times
Grammar
Array GetData ([int timestamp])
eg
$now =getdate ();
$year = $now ["Year"];
$month = $now ["Month"];
Gettimeofday
Time to get current (including GMT)
Grammar
Array gettimeofday (void)
eg
$time =gettimeofday ();
4. String processing function
Explode
Splits a string into an array according to the specified delimiter
Grammar
Array explode (string separator,string string[,int limit])
eg
$str = "A,b,c";
$res =explode (",", $str);//$res [0]=a
Implode
Concatenate the contents of an array into a string
Grammar
String implode (string Glue,array pieces)
eg
$newarray =array (' A ', ' B ', ' C ');
$res =implode (",", $newarray);//$res =a,b,c
Strlen
Gets the length of the string
Grammar
int strlen (String string)
eg
strlen ("www.gxnu.edu.cn");//Pass back 15
Substr
Gets a partial character (substring) specified by the string
Grammar
String substr ("www.gxnu.edu.cn", 1,7); Back to "Ww.gxnu"
5. Mathematical function Library
Ceil
Carry the decimal part of a floating-point number unconditionally
Grammar
float ceil (float value)
eg
Echo Ceil (9.99);//Return 10
echo ceil (9.12);//Return 10
Cos
Gets the cosine of a floating-point value
Grammar
float cos (float arg)
eg
$numcos =cos (0.5);
Floor
Remove the decimal part of the floating-point number unconditionally
Grammar
Float floor (floor value)
eg
echo Floor (9.12);//Return 9
Echo Floor (9.99);//Return 9
Rand
Generate a range of random values
Grammar
int rand ([int min,in Max])
eg
$num =rand (0,100);//Generate a random number between 1 and 100
Round
Rounding the decimal part of a floating-point number to carry
Grammar
Float round (float value)
eg
Float Round (9.99)//return 10
Float round (9.12)//Return 9
Sin
Get the sine of a floating-point value
Grammar
Float sin (float arg)
eg
$numsin =sin (0.5);
6. Session function
Session_register
Describe one or more variables in a session
Grammar
BOOL Session_register (mixed name[,mixed ...])
eg
$name = "Flag";
Session_register ("name");
Session_Start
Initializing session information
Grammar
BOOL Session (void)
eg
Session_Start ();
7. Array functions
Count
There are several array functions in the computed array
Grammar
int count (mixed var[,int mode])
eg
Count ($array);
List
Assigning an element value in an array to a variable
Grammar
void list (mixed varname,mixed ...)
eg
$array =array (A,B,C);
List ($str 1, $str 2, $str 3) = $array;//$str 1=a
Range
Create an array within the specified range
Grammar
Array range (int low,int high[,int Step])
eg
$array =array (0,9);
Shuffle
Re-randomly sort elements in an array
Grammar
BOOL Shuffle (array array)
eg
Shuffle ($array);
http://www.bkjia.com/PHPjc/324160.html www.bkjia.com true http://www.bkjia.com/PHPjc/324160.html techarticle PHP Concise function topic: class bacteria PHP concise function Brief: PHP simple and clear function syntax for the crowd: interested in the open source community, interested in PHP, have a little time to understand the following PHP notes: ...