【发布时间】:2017-12-28 14:35:21
【问题描述】:
对不起……!我的英文不是很好! 直到上周我使用“www.000webhost.com”虚拟主机,我没有问题!!! 但是今天我买了一台新服务器并像以前一样使用旧文件... 我不知道问题出在php文件还是数据库?
请告诉我解决方案
这是我的 php 代码
<?php
//Creating a connection
$con = mysqli_connect("___","___","___","___");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/*Get the id of the last visible item in the RecyclerView from the request and store it in a variable. For the first request id will be zero.*/
$id = $_GET["id"];
$sql= "Select * from db_app where id between ($id+1) and ($id+10)";
$result = mysqli_query($con ,$sql);
while ($row = mysqli_fetch_assoc($result)) {
$array[] = $row;
}
header('Content-Type:Application/json');
echo json_encode($array);
mysqli_free_result($result);
mysqli_close($con);
?>
这是我的数据库代码
CREATE DATABASE `android_db`;
USE `android_db`;
CREATE TABLE IF NOT EXISTS `db_app` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`movie_name` varchar(45) NOT NULL,
`movie_image` varchar(10000) NOT NULL,
`movie_genre` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
);
【问题讨论】:
-
阅读整个帖子stackoverflow.com/questions/279170/utf-8-all-the-way-through 你的答案很可能在里面。
-
在你使用它的时候也可以通过How to Ask。
-
使用
utf8mb4作为数据库列并设置连接的字符集,如@Ray Hong 在答案中所说。 注意,如果您将 Unicode 文本存储到非 Unicode 列,MySQL 会将字符更改为?,您将永远丢失这些字符。不管你做了什么 -
@Accountant_م 我收到此错误 致命错误:在 null 上调用成员函数 set_charset()
-
@FarshadAsgharzadeh 这是因为对象
$mysqli没有创建。您必须首先在代码中创建对象$mysqli = new mysqli("example.com", "your_user_name", "your_password", "your_database_name");,该对象称为$con,将$mysqli替换为$con