离子编码不能与php发布

时间:2015-11-06 16:50:53

标签: php android mysql

我试图在php上发帖并保存在mysql数据库中

这是ION.with命令:

Ion.with(this)
                            .load("http_my_page/test.php")
                            .setBodyParameter("text", "não")


                            .asString(Charset.defaultCharset())//default=UTF-8
                            .setCallback(new FutureCallback<String>() {
                                @Override
                                public void onCompleted(Exception e, String result) {

                                }


                            });

my test.php page:

<?php
$test  = $_POST["text"]; 
$servername = ...;
$username = "..";
$password = "...";
$dbname = "...";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO test (my_test) VALUES ('$test')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

我的MYSQL数据库有一个名为my_test的列,collat​​ion是UTF8_unicode_ci

我的存储内容:“não”

它真正存储的内容:“não”

任何原因?因为即时通讯设置所有经常=(

1 个答案:

答案 0 :(得分:0)

这是一个PHP / MYSQL编码问题,与Ion

无关
$conn->set_charset("utf8");