Home > Backend Development > PHP Tutorial > php数据库链接

php数据库链接

WBOY
Release: 2016-06-23 13:19:44
Original
857 people have browsed it

//数据库连接

define('DB_HOST','localhost');

define('DB_USER','root');

define('DB_PWD','root');

define('DB_NAME','rsp_hts');


//创建数据库连接

$_conn = @mysql_connect(DB_HOST,DB_USER,DB_PWD) or die('数据里连接失败');


//选择一款数据库

mysql_select_db(DB_NAME) or die('指定的数据库不存在');


//选择字符集

mysql_query('SET NAMES UTF8') or die('字符集错误');


//执行一条sql语句

mysql_query("SELECT tg_username FROM tg_user WHERE tg_username='{$_clean['username']}'") or die('SQL错误');


Related labels:
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