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

Basic code and process for operating database in php

无忌哥哥
Release: 2018-06-27 14:55:35
Original
2590 people have browsed it

1. Connect to the database

$link = mysql_connect(server,user,password)
Copy after login

Returns a connection ID, returns false on failure

2.Set the connection code

mysql_set_charset('utf8',$link)
Copy after login

3.Select the database

mysql_select_db(database,$link)
Copy after login

4. Execute sql command

$result = mysql_query(sql)
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template