好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php如何进入数据库

在wamp目录下的WWW下创建一个后缀名为PHP的记事本文件

输入以下代码 (推荐学习:PHP视频教程)

<?php
$con=mysql_connect("localhost:3306","用户名(默认root)","密码");
if(mysql_error())
{
echo"数据库连接失败";
die();//终止运行
}
mysql_select_db("数据库名",$con);
if(mysql_errno())
{
echo"数据库连接失败";
die();
}
echo"数据库连接成功";
?> 

要写sql语句的话

例如:

<?php
$con=mysql_connect("localhost:3306","root","root")
or die("数据库连接失败<br>");
mysql_select_db("mysql_test",$con) or die("数据库连接失败!<br>");
mysql_query("set names 'gbk'");//设置中文字符
$sql = "insert into customers(cust_id,cust_name,cust_sex,cust_address,cust_contact)";
$sql=$sql."values(null,'李中华','0','深圳市','南山区')";
if(mysql_query($sql,$con)){
echo"数据库连接成功<br>";
}
else{
echo"数据库连接失败<br>";
}
?> 

以上就是php如何进入数据库的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于php如何进入数据库的详细内容...

  阅读:43次