一个简单链接数据库并插入表的例子
<?php$dbhost = "localhost:3306"; // mysql服务器主机地址
$dbuser = "root"; // mysql用户名
$dbpass = "123456"; // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die("连接失败: " . mysqli_error($conn));
}
echo "连接成功<br />";
// 设置编码,防止中文乱码
mysqli_query($conn , "set names utf8");
$runoob_title = "学习 Python";
$runoob_author = "RUNOOB.COM";
$submission_date = "2016-03-06";
$sql = "INSERT INTO runoob_tbl ".
"(runoob_title,runoob_author, submission_date) ".
"VALUES ".
"("$runoob_title","$runoob_author","$submission_date")";
mysqli_select_db( $conn, "RUNOOB" );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die("无法插入数据: " . mysqli_error($conn));
}
echo "数据插入成功
";
mysqli_close($conn);
?>
以上是 一个简单链接数据库并插入表的例子 的全部内容, 来源链接: utcz.com/z/533230.html