5.MySQL database Operation steps

Source: Internet
Author: User
Tags urlencode alphanumeric characters what array

First step: Log in to MySQL Server

Step two: Select the database you want to work with now

Step three: Set the character set of the request and return data

Fourth Step: Execute SQL Statements

L Add record: INSERT into News (title,content) VALUES (' title ', ' content ')

L Delete Record: Delete from news WHERE id=180

L Modify Record: UPDATE news SET title = ' new title ', content = ' new content ' WHERE id=180

L Query record: SELECT id,title,hits from News WHERE id<100 ORDER by id desc LIMIT 10,10

To Import test Data saixinjituan.sql steps

steps for php+mysql database programming

L First step:PHP connection to MySQL Server

L Second Step: Select the database you want to work with now

L Step Three: Set the character set of the requested or returned data

L Fourth Step: Execute various SQL statements.

PHP Connection to MySQL server

1,mysql_connect ()

L Description:PHP connects to MySQL server.

L Syntax:resource $link = mysql_connect ($hostname, $username, $password)

L Parameters:

U $hostname: is the domain name or IP address of the MySQL server . You can also add a port number (3306). such as:localhost:3306

U $username: is The user name of the MySQL server. such as:root

U $password: is the MySQL Server user password. such as:root

L return value: Returns a resource identifier if execution succeeds. Returns FALSE if the execution fails .

2.exit ()

L Description: Output a message and abort the script to continue running down.

L Syntax:void exit ([$msg])

L parameter:$msg is optional. If omitted, only the script run is aborted.

L Example: Exit (" error in PHP connection ")

3,mysql_error ()

L Description: Returns the text error message of the last MySQL execution Failure .

L Syntax:mysql_error ()

4, shielding system error @

Description:@ can mask various function call errors, or contain file errors, but cannot be used before function definitions or class definitions.

Select MySQL database

mysql_select_db ()

L Description: Select the database that you want to manipulate now

L Syntax: bool mysql_select_db (String $database _name [, Resource $link])

L Parameters:

U $database _name: Specifies the name of the database to select.

U $link: Optional. Specifies the current active connection. If omitted, the active connection is open on the previous one.

L return value: Returns TRUE if the database selected is successful . Returns FALSE if the database selection fails .

Set The data character set returned by MySQL

mysql_query ("set names UTF8")

Description: To The MySQL server sends a request or returns the data character set of the request result.

mysql_query ()

L Description: Send a MySQL query.

L Syntax:resource mysql_query (string $query [, Resource $link = NULL])

L Parameters:

U $query: refers to the SQL statement to be sent .

N Add Record: $query = "INSERT into News (title,content) VALUES (' title ', ' content ')"

N Delete Record: $query = "Delete from news WHERE id=10"

N Modify Record: $query = "UPDATE News SET title = ' new title ', content = ' new ' where id=80 '

N Query record: $query = "SELECT * FROM news WHERE id<100"

U $link: Optional. Refers to the last active connection that was opened.

L return value

If you execute the Select,SHOW,DESCRIBE command, the result set is returned on success and FALSE on failure .

The U result set is also a resource identifier, which is a reference address to MySQL data.

If you execute a different SQL statement, the execution returns TRUEsuccessfully, and the execution failure returns FALSE.

L Example:

U $result = mysql_query ("SELECT * FROM News WHERE id<100")

U $result = mysql_query ("DELETE from News WHERE id=100")

To fetch a row of data from the result set

1,mysql_fetch_row ()

N Description: Gets a row from the result set as an enumeration array.

n Syntax:array mysql_fetch_row (resource $result)

n parameter:$result is a result set variable.

n return value: Returns an enumerated array, which is a positive integer subscript starting at 0. The subscript here is corresponding to the table's field subscript.

n Example: $arr = Mysql_fetch_row ($result)

2,mysql_fetch_array ()

U description: Takes a row out of the result set and returns as a mixed array.

U syntax:array mysql_fetch_array (resource $result [, int $ result_type])

U parameter:

U $result: refers to the result set variable.

U $result _type: Refers to the type of the returned array. Value:mysql_both,mysql_assoc,mysql_num

N mysql_both: Default. That is, both subscripts exist.

N MYSQL_ASSOC: An array of only character subscripts. Equivalent to the function of MYSQL_FETCH_ASSOC ().

N mysql_num: An array of only integer subscripts. Equivalent to the function of mysql_fetch_row ().

n more than three parameters are constants, system constants must be all uppercase.

U return value: Returns an array, as to what array, depending on the second argument.

u Example:

U $arr = mysql_fetch_array ($result)// mixed array

U $arr = mysql_fetch_array ($result, MYSQL_ASSOC)// associative array

U $arr = mysql_fetch_array ($result, Mysql_num)// Enumeration Array

3,mysql_fetch_assoc ()

U description: Takes a row from the result set and returns it as an associative array.

U syntax:array mysql_fetch_assoc (resource $result)

u example: $arr = Mysql_fetch_assoc ($result)

PHP function Supplement

1.include syntax structure

L Description: Contains and runs the specified file.

L Syntax: include $filename or include ($filename)

L Example: include "include/conn.php"

PHP function Supplement

1.include syntax structure

L Description: Contains and runs the specified file.

L Syntax: include $filename or include ($filename)

L Example: include "include/conn.php"

2.require grammatical structure

L Description: Contains and runs the specified file.

L Syntax: Require $filename or require ($filename)

L Example:require "include/conn.php"

Note:include and require are both included and run files, but there is a difference.

If the included file does not exist,include will report a warning error and the script continues to run down.

require will report a fatal error, and the script will immediately terminate execution.

3.Header ()

L Description: send a custom http message , in other words:the format or character set of the data returned by PHP.

L Syntax:void Header (string $string)

L Example:

U header ("Content-type:text/html;charset=utf-8")// set The character set of PHP return data

U header ("location:http:www.sina.com.cn"); page Jump

jump inu JS: location.href = "http://www.sina.com.cn"

U HTML Jump:<meta http-equiv = "Refresh" content = "2;url = http://www.sina.com.cn" >

URL Uniform Resource Locator.

http://www.sina.com.cn/index.php ? Username=yao & Userpwd=123456#top

? before is the file name. ? followed by a query string.

query string:? username=yao&userpwd=123456//location.search

after the query string, it is the anchor name. such as:#top

3.Header ()

L Description: send a custom http message , in other words:the format or character set of the data returned by PHP.

L Syntax:void Header (string $string)

L Example:

U header ("Content-type:text/html;charset=utf-8")// set The character set of PHP return data

U header ("location:http:www.sina.com.cn"); page Jump

jump inu JS: location.href = "http://www.sina.com.cn"

U HTML Jump:<meta http-equiv = "Refresh" content = "2;url = http://www.sina.com.cn" >

URL Uniform Resource Locator.

http://www.sina.com.cn/index.php ? Username=yao & Userpwd=123456#top

? before is the file name. ? followed by a query string.

query string:? username=yao&userpwd=123456//location.search

after the query string, it is the anchor name. such as:#top

UrlEncode ()

Description: encoded URL string

Syntax: String UrlEncode (String $str)

Description: Returns the string, in addition to-_, in this string . all non-alphanumeric characters will be replaced with a percent ( % ) followed by a two-digit hexadecimal number, the space is encoded as a plus sign ( + ).

Example:urlencode (" period ") =%e7%ac%ac32%e6%9c%9f

UrlDecode ()

Description: decoding an encoded URL string

Syntax: string urldecode (String $str)

5.MySQL database Operation steps

Related Article

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.