原生php如何输出mysql最后执行的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);
?>
echo $sql;