代码很简单直接上了
<?php /** * @Author: HTL * @Email: [email protected] * @DateTime: 2015-05-14 16:00:08 * @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("<BR>---------------------------mysql_connect------------------------<BR><BR>"); $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("<BR>---------------------------mysqli_connect------------------------<BR><BR>"); $conn = mysqli_connect($db_host, $db_user, $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(); ?>
有图有真相
参考:
时间: 2024-10-07 22:40:25