PHP database Common functions of the detailed

Source: Internet
Author: User
Tags php database
This article mainly with you to share PHP database commonly used in the function of the detailed, hope to help everyone.
Array functions
Extract ()
You can convert the subscript in an associative array to a variable using the

$stu = array (' ID ' =>1, ' name ' =>loser), then the ID and name can be used as a variable $id, $namekey () Gets the key name from the associative array current () returns the active cell in the array next () Moves the inner pointer in the array forward one end () points the pointer to the last element prev () Moves the inner pointer in the array backward one each () returns the current key/value pair in the array and moves the array pointer forward one step, if the inner pointer crosses the end of the array to return Falselist () Assigns the value in the array to the variable $arr = array (' Tom ', ' David '), List ($one, $two) = $stu; Range (A, B) generates an array of a-a, in reverse or {{Array_merge () arrays Array_ Merge (range (0,1), range (' A ', ' Z '), Range (' A ', ' Z ')) Summary: Array merge when the label conflicts, Follow these rules to resolve 1. If it is a string subscript, the following element overrides the preceding element by 2. If it is an integer subscript, re-establish the subscript (redefined in order of 0,1,2,3) array_merge_recursive () array merge, with Array_ Merge is not much different the biggest difference is that when a key name is duplicated, Array_merge () overwrites the element with the same key name and array_merge_recursive () combines elements of the same key name into a new array}}{{array_rand ( Array, the number of random elements taken out of the array, the elements in the random array, return the subscript of random arrays if you randomly take one, return an integer subscript if you randomly remove multiple, return integer subscript array (A, B, C)}}{{shuffle (array) scrambled array}}{{array key value function [[ Array_keys ($array) returns all the key names in the array array_values ($array) returns all the values in the array, both of which are]][[array_combine in the form of an array ($array 1, $array 2) Combine two arrays, the value of the first array is the key name, the value of the second array is the value if the key array and the number of values are inconsistent, an error]][[in_array (value, $array) to see if the value is in the array $array if it exists, returns true if it does not exist, Returns false case insensitive data type]][[array_key_exists (key, $array) see if the array contains a key value type withOn]]}}{{}} ******************************************************//********************************************** The normal function sleep (parameter) delay execution parameter is the number of seconds ******************************************************//************************ Database functions mysql_connect (' localhost ', ' username ', ' pwd ') Connecting to the database The first parameter indicates the connection address the second parameter indicates the user name the third parameter represents the password {{connection database mysql_connect (' host address: [Port number] ', ' username ', ' password ') Select Database mysql_query (' Use database name ') mysql_select_db (database name) setting execution Environment mysql_query (' Set names UTF8 ')}}{{view database name (match lookup) show databases like "%***%";% refers to match, In front of it is the match starting with the first match from the name, followed by the match from the name behind the}}{{create database created by;}} {{#增加用户 # Format: Grant permission on database. * To User name @ Login host identified by ' Password '} {{{} Delete and change (statement) #创建数据库create database tb_name; #删除数据库drop database tb_name; #使用该数据库use tb_name; #显示数据库中的表show tables;# First determine if the table exists, the existence of delete drop table if exists student; #创建表create table student (id int auto_increment primary key,name varchar (), SE x varchar (), date varchar ((), content varchar ()) default Charset=utf8; #删除表drop table student; #查看表的结构describe  Student #可以简写为dESC student; #插入数据insert into tb_name values (' * * * ', ' * * * ', ' * * * '); #查询表中的数据select * from Tb_name;select id,name from Tb_name ; #修改某一条数据update tb_name set sex= ' man ' where id=4; #删除数据delete from student where id=5; #蠕虫复制//Let the database grow exponentially//insert duplicate data, No significant business significance, mainly used to test the pressure of the data sheet or the efficiency of the index insert into tb_name (field) select field from Tb_name;}} Determines whether a variable is an empty collection isset () determines whether the variable is set and the value set is not NULL if the return value is created, then the return value is Trueempty () to determine whether the variable is empty to determine whether the data type collection is_numeric () is a numeric or numeric string Is_arr Ay () determines whether the array is_string () determines whether the string Is_int () determines whether the shape is is_double () determines whether a floating-point type Is_bool () determines whether the bool type is a string function is_string () Determines whether the string strlen ($num) determines the length of the variable (string) implode (delimiter, $array) stitching the values in the array into a string explode (delimiter, $array) to cut the string by the delimiter [[ Strings can be understood as a collection of characters (arrays), so can be accessed by [], cannot manipulate Chinese]][[strlen () returns the length of the string note: In GBK the next Kanji account for two bytes, in Utf-8 the next Kanji account for three bytes]][[Remove the space function trim (), LTrim (), RTrim () first remove the space before and after the second to remove the left space, the third to remove the right space]][[strpos (string, ' str ') to find the position of STR in the string, starting from the left, find the first occurrence of the position strrpos (string, ' Str '), the difference is from the beginning to find the first occurrence of the position, but the return value is also the number of]][[str_repeat ($STR, num) repeats the string several times $word = str_repeat (' Hello ', 3);] [[Ord () Gets the ASCII code of the character Chr () turns the ASCII code into a character]] [[


Intercept string
SUBSTR (string, start position, intercept length)
If the start position is a negative number, start with 1, and if it is an integer, start at 0
If the intercept length is empty, then the default is to intercept the last
If the intercept length is negative, it means that the following characters do not intercept
STRCHR (String, ' str ')
Intercept in string according to Str
$str = ' ABCCBA ';
Echo strchr ($str, ' B '); Result:bccba
STRRCHR (String, ' str ')
The rule is the same, the difference is from the right.
Str_replace (' Strone ', ' strtwo ', $str) Replace string
In $str, replace Strone with Strtwo
Replace multiple strings at once
In the form of an array
$str = ' Tomorrow is a day, and tomorrow is much ';
Str_replace (Array (' Tomorrow ', ' complex '), array (' 1 ', ' 2 '), $STR);
Result: "12 tomorrow, 1 more"
Note: If no one by one corresponds, then the first array of
All elements are replaced with a second argument
Str_split ($array, num)
To split a string into an array
Num refers to a number of values in each array element
Str_pad (string, Length, ' supplement ')
string padding, padding a string to a specified length, insufficient to fill with a "supplemental value"
Plus Str_pad_left will start from the left.
Add Str_pad_both in the back and start from both sides.
String Case Conversion
Strtolower ()
All strings converted to lowercase
Strtoupper ()
All strings are converted to uppercase
NL2BR ()
Converts a string into a line <br>
Htmlspecialchars ()
Convert a string to an entity
]]
Sort function
Sort ()
Sorting elements in an array in ascending alphabetical order
Rsort ()
Sorting elements in an array in descending alphabetical order
Object oriented

{{} Add property directly with $str-> new property name = ' str ';}} {{Delete property unset ($str-property name)}} {{Isset property name is determined if the property exists ($str--)}} {{instanceof is used to determine if a variable belongs to a data type class student{} $stu = new Student;var_dump ($stu instanceof Student);}}

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.