gpt4 book ai didi

php - 错误 '.$row["column_name_here"]。'编码

转载 作者:行者123 更新时间:2023-11-29 13:01:54 25 4
gpt4 key购买 nike

我对 PHP 有点陌生。我实现了http://www.sanwebe.com/2013/03/loading-more-results-from-database我的新网站中的解决方案:http://do2go.pl/do2go-nowa/

它运行良好 - 除了编码之外。我的数据库和所有东西都是UTF8格式的。当 fetch 从 DB UTF8 获取数据时似乎不起作用。

这里是配置和获取代码:

配置:

<?php
$db_username = 'kamio2_do2gonowa';
$db_password = 'JeremiasZ1!';
$db_name = 'kamio2_do2gonowa';
$db_host = 'localhost';
$item_per_page = 2;
mysqli_query ("SET NAMES 'utf8'"); mysqli_set_charset('utf8');


$connecDB = mysqli_connect($db_host, $db_username, $db_password,$db_name) or die('could not connect to database');


?>

并获取:

<?php
include("config.inc.php"); //include config file
//sanitize post value
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
header('Content-Type: text/html; charset=UTF-8');

//throw HTTP error if page number is not valid
if(!is_numeric($page_number)){
header('HTTP/1.1 500 Invalid page number!');
exit();
}

//get current starting point of records
$position = ($page_number * $item_per_page);

//Limit our results within a specified range.
$results = mysqli_query($connecDB, "SELECT id,introtext FROM w7wst_content ORDER BY id DESC LIMIT $position, $item_per_page");

//output results from database

echo '<ul class="page_result">';
while($row = mysqli_fetch_array($results))
{
echo '<li id="item_'.$row["id"].'"><span class="page_message">'.$row["introtext"].'</span></li>';
}
echo '</ul>';

?>

我添加了mysql_query("SET NAMES 'utf8'"); mysql_set_charset('utf8'); 但这什么也不做。仍然得到 � 符号和 ?而不是“所有接下来的 3 个都直接在数据库表中更改为 html 符号,这不是解决方案。

任何帮助表示赞赏! :)

最佳答案

(结束问题,因为这是OP问题的解决方案)

$results = mysqli_query($connecDB...之前添加$connecDB->set_charset("utf8");

关于php - 错误 '.$row["column_name_here"]。'编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23226506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com