1.最简单的方式
| 1 | <span style="font-family:'微软雅黑', 'Microsoft YaHei';font-size:14px;color:rgb(0,0,0);"><?php<br>$con = mysql_connect("localhost","root","");<br>if (!$con)<br> {<br> die('Could not connect: ' . mysql_error());<br> }<br>mysql_close($con);<br>?><br></span> |
2.面向对象mysqli
| 1 | <span style="font-family:'微软雅黑', 'Microsoft YaHei';font-size:14px;color:rgb(0,0,0);"><?php<br>$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');<br>try {<br> foreach ($db->query('select * from user') as $row){<br> print_r($row);<br> }<br> $db = null; //关闭数据库<br>} <br> catch (PDOException $e) {echo $e->getMessage();<br>}<br>?><br></span> |
3.pdo连接mysql
| 1 | <span style="font-family:'微软雅黑', 'Microsoft YaHei';font-size:14px;color:rgb(0,0,0);"><?php<br>$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');<br>try {<br> foreach ($db->query('select * from user') as $row){<br> print_r($row);<br> }<br> $db = null; //关闭数据库<br>} <br>catch (PDOException $e) {<br> echo $e->getMessage();<br>}<br>?></span> |
4.ADODB连接mysql
| 1 | <span style="font-family:'微软雅黑', 'Microsoft YaHei';font-size:14px;color:rgb(0,0,0);"><?php<br>require_once './adodb5/adodb.inc.php';<br>$conn = &ADONewConnection('mysql');<br>$conn->connect('localhost','root','','test');<br>$conn->Execute("set names utf8");<br>$res = $conn->Execute("select * from user");<br>if (!$res){<br> echo $conn->ErrorMsg();<br>}else{<br> var_dump($res);<br>}<br>?></span> |
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦