<?php
header("Content-type:text/html;charset=utf-8");
$host='127.0.0.1';
$user='root';
$pass='';
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);//关闭数据库链接
?>
PHP学习记录_mysql连接
最新推荐文章于 2024-04-30 13:26:55 发布