Home  >  Article  >  php教程  >  简单学习PHP向MYSQL中插入数据的代码

简单学习PHP向MYSQL中插入数据的代码

WBOY
WBOYOriginal
2016-06-13 10:29:221210browse

简单学习PHP向MYSQL中插入数据的代码

$dbhost = localhost;
$dbuser = webjxcom; //你的mysql用户名
$dbpass = 123456; //你的mysql密码
$dbname = database; //你的mysql库名

//连接本地数据库
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if ($conn) {
echo "连接数据库成功";
} else {
echo "连接数据库失败";
}
//打开数据库
mysql_select_db($dbname,$conn);
//插入数据
$sql="insert into test(test) values(ddddddd)";
$result=mysql_query($sql,$conn)or die(mysql_error());

echo "打开数据库";
//关闭数据库
mysql_close($conn);
?> 


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