PHP learning record_mysql connection

WBOY
Release: 2016-08-08 09:26:58
Original
784 people have browsed it
<?php
header("Content-type:text/html;charset=utf-8");
 $host=&#39;127.0.0.1&#39;;
 $user=&#39;root&#39;;
 $pass=&#39;&#39;;
 if($con=mysql_connect($host,$user,$pass)){//连接成功,返回ture,失败:false;
	 echo "连接数据库成功";
 }
 else {
	 echo "连接数据库失败";
 }
 echo "<br/>";
 if(mysql_select_db('wensay')){
	 echo "选择数据库成功";
 }//选择数据库
 else{
	 echo "选择数据库失败";
 }

 mysql_query("set names 'utf-8");//设置当前链接使用的字符编码
 if(mysql_query('insert into test(name)value("abc")')){//insert 成功,返回ture,失败,返回false;
	 echo "插入成功";
 }
 else {
	 echo mysql_errno();
	 echo  "插入失败";
 }
 mysql_close($con);//关闭数据库链接
?>
Copy after login

The above introduces the PHP learning record_mysql connection, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!