这是关于从Mysql表中以CSV格式重新获取数据: -
代码,我试过了: -
<?php
// mysql database connection details
$host = "localhost";
$username = "root";
$password = "hello";
$dbname = "mysql2csv";
// open connection to mysql database
$connection = mysqli_connect($host, $username, $password, $dbname) or die("Connection Error " . mysqli_error($connection));
// fetch mysql table rows
$sql = "select * from tbl_books";
$result = mysqli_query($connection, $sql) or die("Selection Error " . mysqli_error($connection));
$fp = fopen('books.csv', 'w');
while($row = mysqli_fetch_assoc($result))
{
fputcsv($fp, $row);
}
fclose($fp);
//close the db connection
mysqli_close($connection);
&GT;
获得的错误......
04:12:27.093未声明HTML文档的字符编码。如果文档包含US-ASCII范围之外的字符,则文档将在某些浏览器配置中使用乱码文本进行渲染。必须在文档或传输协议中声明页面的字符编码.1 mysql2csv.php。
您的帮助将不胜感激......
答案 0 :(得分:0)
将这些行添加到您的html标题
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
修改强> 如果您使用的是PHP文件:
header('Content-Type: text/html; charset=utf-8');