原生php如何输出mysql最后执行的sql

2025-03-10 13:53:58
推荐回答(2个)
回答1:

$sql = 'XXXX';
echo $sql;

回答2:

$dbhost = 'localhost:3306'; // mysql服务器主机地址
$dbuser = 'root'; // mysql用户名
$dbpass = '123456'; // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接失败: ' . mysqli_error($conn));
}
// 设置编码,防止中文乱码
mysqli_query($conn , "set names utf8");

$sql = 'SELECT runoob_id, runoob_title,
runoob_author, submission_date
FROM runoob_tbl';

mysqli_select_db( $conn, 'RUNOOB' );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die('无法读取数据: ' . mysqli_error($conn));
}
//这下面是重点输出
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC))
{
echo " {$row['runoob_id']} ".
"{$row['runoob_title']} ".
"{$row['runoob_author']} ".
"{$row['submission_date']} ".
"";
}
echo '';
mysqli_close($conn);
?>