PHP
$dbhost = "localhost:3306"; // Mysql服务器主机地址
$dbuser = "root"; // mysql用户名
$dbpass = "123456"; // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die("连接失败: " . mysqli_error($conn));
}
echo "连接成功
";
// 设置编码,防止中文乱码
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);
?>
--结束END--
本文标题: 一个简单链接数据库并插入表的例子
本文链接: https://lsjlt.com/news/5629.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0