Home  >  Article  >  Backend Development  >  php与Mysql

php与Mysql

WBOY
WBOYOriginal
2016-06-20 12:35:10879browse

1.打开phpMyAdmin

http://localhost/phpmyadmin


2.建立连接

$con=mysql_connect($db_host,$db_user,$db_pass)

3.关闭连接

mysql_close($con);


4.打开数据库(该数据库应该在phpmyadmin中创建)

if(mysql_select_db(web_01)){	echo "选择数据库成功";}else{	echo "选择数据库失败";}
5.执行sql语句

在数据库建立连接以后就可以进行查询,采用mysql_query加sql语句的形式向数据库发送查询指令。

if(mysql_query('insert into  my_table(name) values("taylor")')){	echo "<br>"."插入成功";	}else{	echo "<br>"."插入失败";}

向my_table表里面的name 属性插入值为"taylor"的字段.

6.sql语句出错信息打印

echo mysql_error();
7.防止中文乱码

mysql_query('set names utf8');






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