PHP introductory learning knowledge point 1 PHP and MYSql connection and query_PHP tutorial

WBOY
Release: 2016-07-21 15:27:01
Original
702 people have browsed it

1. Connect to the database
1. mysql_connect: Open the MySQL link

mysql_connect('host', 'username', 'password')

2. mysql_select_db : Open a database
mysql_select_db('database name',$link identifier) ​​//If the link identifier is not filled in, it will default to the last opened connection

3. mysql_query("set names 'GBK' ") Solve the problem of Chinese garbled characters;

 mysql_query("set names 'Encoding (utf8 or GBK)' ") //UTF8 cannot have "-"

2. Query data

1. mysql_query (SQL statement, connection identifier);

$sql="Select * FROM Test "
$result=mysql_query($sql) //Connection identifier The symbol defaults to the last opened link

//Get error information

$result=@mysql_query($sql) or die(mysql_error())

2. Get Query results

a. mysql_fetch_row($result);

$row=mysql_fetch_row($result);
echo $row[0];

b , mysql_fetch_array($result);

$row=mysql_fetch_array($result);
echo $row[0];
echo $row['key'];


Note: The functions of mysql_fetch_array and mysql_fetch_row are basically the same, except that in addition to using offsets starting from 0 as index, it can also use domain names as index.
The value returns all the field values ​​​​of the next row and saves them in an array. If there is no row, it returns false.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323835.htmlTechArticle1. Connect to the database 1. mysql_connect: Open the MySQL link mysql_connect('host','username','password ') 2. mysql_select_db: Open a database mysql_select_db('Database name...
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