简体   繁体   中英

mysqli_query() expects parameter 1 to be mysqli boolean given while inserting unicode data to database

I want to insert unicode data to database so user the function $mysqli=mysqli_set_charset($con,'utf-8'); what is wrong with it? I couldn't solve this.

function insert(){

    $con = mysqli_connect('localhost','root','','db_darta');
    $mysqli=mysqli_set_charset($con,'utf-8');
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    exit();
    }
    mysqli_query($mysqli,"insert into tbl_darta (fiscal_year, darta_no, darta_date, patra_date, paper_from, letter_recievedby, subject, file_upload, remarks, created_by, created_date, section) values ('$this->fiscal_year', '$this->darta_no', '$this->darta_date', '$this->patra_date', '$this->paper_from', '$this->letter_recievedby', '$this->subject', '$this->file_upload', '$this->remarks','$this->created_by','$this->created_date','$this->section')");
}

In your query you passing argument which Return Value: TRUE on success. FALSE on failure.

mysqli_query({database connection object}, {your desired query})

    function insert(){

    $con = mysqli_connect('localhost','root','','db_darta');
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    exit();
    }
    mysqli_set_charset($con,"utf8"); // returns true or false
    mysqli_query($con,"insert into tbl_darta (fiscal_year, darta_no, darta_date, patra_date, paper_from, letter_recievedby, subject, file_upload, remarks, created_by, created_date, section) values ('$this->fiscal_year', '$this->darta_no', '$this->darta_date', '$this->patra_date', '$this->paper_from', '$this->letter_recievedby', '$this->subject', '$this->file_upload', '$this->remarks','$this->created_by','$this->created_date','$this->section')");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM