0

I have an article in MySQL which has a title column. Now the title column for a specific article id has characters You’. When I query this article PHP does not return anything at all and the screen is completely blank. "View source" also doesn't show anything.

Here is the code:

static function getArticle($params) 
{
    $id=$params['article_id'];
    $queryv = "SELECT * FROM 'articles WHERE `article_id`='{$id}'";

    $resultv = mysql_query($queryv) or die(json_encode(mysql_error()));
    if (mysql_num_rows($resultv) > 0) 
        {   

            $row = mysql_fetch_assoc($resultv);
            $title=strtoupper($row['article_title']);
            $body=$row['article_body'];
            return(array('article_id'=>$row['article_id'],
                'article_body'=>"<h3 style='width:100%;text-align:center;'>$title</h3>$body",
                'article_title'=>$row['article_title'],
                'article_author'=>$row['article_author'],
                'article_image'=>$row['article_image'],
                'article_share_link'=>$row['article_share_link'],
                'article_author_image'=>$row['article_author_image'],
                ));
        }   
}

I'm using utf8mb4_general_ci as collation in MySQL. phpmyadmin does return the correct result.

I did search online before posting this question but nobody had this problem of getting absolutely no response.

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
Abdul Qadeer
  • 374
  • 3
  • 15
  • It would be nice to edit your question and add the code you've written so far : [How to create a Minimal, Complete, and Verifiable example ?](http://stackoverflow.com/help/mcve). – Ivan Gabriele Jun 22 '16 at 06:55
  • There are a few places where encoding matters. It's HTML meta tag, real HTML encoding. PHP file encoding, MySQL connection encoding and then database/table/field encoding which you mentioned. There are many possibilities why you fail to find result in MySQL. Good luck with that. ;-) – Jakub Matczak Jun 22 '16 at 07:01
  • PHP error log does not show any result related to my problem actually no entry for todays date exist in php error log.:( – Abdul Qadeer Jun 22 '16 at 07:11
  • 1
    please **don't** use `mysql_...` functions anymore: _Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: mysqli_query() PDO::query()_ (http://php.net/manual/en/function.mysql-query.php) – low_rents Jun 22 '16 at 07:14
  • Yes i Normally use PDO prepared stements for MySQL actually this is someone else's code i am just making modificatons – Abdul Qadeer Jun 22 '16 at 07:32
  • 1
    @aliahmad then this should be the very first thing you should modify: get rid of `mysql_...` functions! – low_rents Jun 22 '16 at 09:43
  • Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Matt Raines Jun 22 '16 at 10:26

1 Answers1

0

set your php char set to utf-8 by using ini_set( 'default_charset', 'UTF-8' ); then try to SELECT CONVERT("You’",char CHARSET utf8) it may work

  • Problem is getting weirder. Now if i do not include article_body in the $result array the response is fine but if i include article_body same problem and if i change value in the article_title and add article_body in response array again result is OK! – Abdul Qadeer Jun 22 '16 at 07:29