本文实例讲述了PHP使用MysqL与MysqLi连接MysqL数据库的方法。分享给大家供大家参考,具体如下:
代码很简单直接上了
PHP;">
PHP
/**
* @Author: HTL
* @Description: Description
*/
// 降低PHP默认的错误级别
// 只显示除禁用以外的所有错误
// 解决因为PHP5.3+版本太高而导致在使用MysqL_connect时出现的弃用警告“Deprecated: MysqL_connect(): The MysqL extension is deprecated and will be removed in the future: use MysqLi or PDO instead”
error_reporting(E_ALL ^ E_DEPRECATED);
$db_host="localhost";
$db_user="root";
$db_passwd="";
$db_name="MysqL";
echo("
---------------------------MysqL_connect------------------------
"); $query = "SELECT SESSION_USER(),CURRENT_USER(),now();"; $conn = MysqL_connect($db_host,$db_user,$db_passwd); if (!$conn) { die('Could not connect: ' . MysqL_error()); } MysqL_select_db($db_name,$conn); $result = MysqL_query($query); while($row = MysqL_fetch_array($result)){ var_dump($row); } MysqL_close($conn); echo("
---------------------------MysqLi_connect------------------------
"); $conn = MysqLi_connect($db_host,$db_passwd,$db_name) ; if (!$conn) { die('Could not connect: ' . MysqLi_error()); } //execute the query. $result = MysqLi_query($conn,$query); //display information: while($row = MysqLi_fetch_array($result)) { var_dump($row); } MysqLi_close($conn); exit(); ?>
---------------------------MysqL_connect------------------------
"); $query = "SELECT SESSION_USER(),CURRENT_USER(),now();"; $conn = MysqL_connect($db_host,$db_user,$db_passwd); if (!$conn) { die('Could not connect: ' . MysqL_error()); } MysqL_select_db($db_name,$conn); $result = MysqL_query($query); while($row = MysqL_fetch_array($result)){ var_dump($row); } MysqL_close($conn); echo("
---------------------------MysqLi_connect------------------------
"); $conn = MysqLi_connect($db_host,$db_passwd,$db_name) ; if (!$conn) { die('Could not connect: ' . MysqLi_error()); } //execute the query. $result = MysqLi_query($conn,$query); //display information: while($row = MysqLi_fetch_array($result)) { var_dump($row); } MysqLi_close($conn); exit(); ?>
有图有真相
更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
原文链接:https://www.f2er.com/php/19433.html