1

My php code is below:

<?php
    $username = "root";
    $password = "";
    $hostname = "localhost";
    $db="newsportaldb";

     $dbhandle = mysql_connect($hostname, $username, $password) 
     or die("Unable to connect to MySQL");
     $selected = mysql_select_db($db,$dbhandle) 
     or die("Could not select DB");
    $sql= mysql_query('select username from tbl_login');
            while($rss= mysql_fetch_array($sql))
                {  
        $ress["homepagecontents"][] = array("titles"=>$rss['username']);
                        }
                    echo json_encode($ress);
        mysql_close($dbhandle);

    ?>
//in this case we getting "?????????????????" as a result of echo json_encode($ress);
Bhupendra Shukla
  • 3,814
  • 6
  • 39
  • 62
Aneesh NN
  • 113
  • 1
  • 9
  • 4
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Rikesh Feb 25 '14 at 06:06
  • Make sure your database connection, table and column have consistent charset, ideally UTF8 – Mike Feb 25 '14 at 06:14

1 Answers1

0

The Question marks come from wrong charset. Make sure that the connection has right charset (utf8). If on phpmyadmin you dont see the data correctly so change the db,table and column to utf8_general_ci. Hot recommend for you: upgrade your code and use php PDO Object. Good luck !

4EACH
  • 2,132
  • 4
  • 20
  • 28