<?php
$rvername = “localhost“;
$urname = “urname“;
$password = “password“;
$dbname = “mydb“;
// 创建连接
//$conn = new mysqli($rvername, $urname, $password);
$conn=newmysqli($rvername,$urname,$password, $dbname);
// 检测连接
if ($conn->connect_error)
{
die(“连接失败: “ . $conn->connect_error);
李云迪女朋友 }
// 创建数据库
$sql = “create databa mydb“;
if ($conn->query($sql) === true)
{
echo “数据库创建成功“;
}el{
echo 专业教育220;error creating databa: “ . $conn->error;
}
$conn->clo();
echo “连接成功“;
?>
<?php
$rvername = “localhost“;
$urname = “urname“;
$password = “password“;
$dbname = “mydb“;
// 创建连接
//$conn = mysqli_connect($rvername, $urname, $password);
$conn=mysqli_connect($rvername,$urname,$password,$dbname);
// 检测连接
if (!$conn) {
die(“connection failed: “ . mysqli_connect_error());
}
// 创建数据库
$sql = “create databa mydb“;
if (mysqli_query($conn, $sql))
{
echo “数据库创建成功“;
} el {
英雄作文600字 echo “error creating databa: “ . mysqli_error($conn);
孝亲尊师 }
mysqli_clo($conn);
echo “连接成功“;
?>
<?php
$rvername = “localhost“;
$urname = “urname“;
$password = “password“;
$dbname = “mydbpdo“;
try {
//$conn = new pdo(“mysql:host=$rvername;“, $urname, $password);
$conn = new pdo(“mysql:host=$rvername;dbname=$dbname“, $urname, $password);
echo “连接成功“;
//设置pdo错误模式为异常
$conn->tattribute(pdo::attr_errmode,pdo::errmode_exception);
$sql=“createdatabamydbpdo”;
//使用exec(),因为没有结果返回
$conn->exec($sql);
echo“数据库创建成功<br>”人民日报摘抄;;} catch(pdoexception $e) {
echo$sql.“<br>”.$e->getmessage();
}
$conn = null;
?>
<?php$dbh = new pdo('mysql:host=localhost;dbname=test', $ur, $pass, array( pdo::attr_persistent => true));?>
本文发布于:2023-04-08 08:48:10,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/ede4bd9fb577756a2f23a942d5ebb725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP连接MySQL.doc
本文 PDF 下载地址:PHP连接MySQL.pdf
留言与评论(共有 0 条评论) |