Home  >  Article  >  Basic code and process for operating database in php

Basic code and process for operating database in php

无忌哥哥
无忌哥哥Original
2018-06-27 14:55:352568browse

1. Connect to the database

$link = mysql_connect(server,user,password)

Returns a connection ID, returns false on failure

2.Set the connection code

mysql_set_charset('utf8',$link)

3.Select the database

mysql_select_db(database,$link)

4. Execute sql command

$result = mysql_query(sql)

If no data is returned, true will be returned if successful, false will be returned if failed

If data is returned, the data set will be returned successfully, false will be returned if failed

5. Commonly used functions

1. mysql_fetch_array(data,array_type) gets a row from the result set as an associative array or a numeric array, or both

data is $result, Result set

array_type: MYSQL_ASSOC: Associative array

MYSQL_NUM: Numeric array

MYSQL_BOTH: By default, both associative arrays and numeric arrays are generated


2. mysql_fetch_assoc(data) gets a row from the result set as an associative array

3. mysql_fetch_row(data) gets a row from the result set as a numeric array

4. mysql_num_fields( data) returns the number of fields in the result set

5. mysql_num_rows(data) returns the number of rows in the result set

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn