title: PHP array_push() doesn't work but array[] does, only without SQL where clause
body: <p>So I have a very odd problem I came across while using SQL clauses and PHP commands. For some reason my code works fine when using the command
  <code>"SELECT * FROM tableName WHERE columnName=text";</code>
  But doesn't work when using
          <code>"SELECT * FROM tableName";</code>
  I've put the SQL command directly into MySQL, and it returns results. If I implode the row array, I get the results, and if I switch from using
          <code>array_push($result...)</code>
  to
          <code>$result= []</code>
  I get the last entry in JSON format, as expected. I'm not sure why I'm getting this behavior, this code I believe worked in a previous version of PHP, or maybe an older version of MySQL. I've done some updates recently and everything is now at the very latest version. Searching found people who had both array_push and array[] not work, or where the command didn't work with the WHERE clause, but I have the opposite issue. Not sure what it could be, I enabled PHP error reporting and SQL error reporting, and I just get the PHP white screen of death when the issue happens.</p>
  
  <pre><code>&lt;?php
  error_reporting(-1);
  define('HOST','localhost');
  define('USER','dbuser');
  define('PASS','dbpassword');
  define('DB','dbname');
  
  $eventYear = isset($_GET["year"]) ? $_GET["year"] : '';
  $eventYear = addslashes($eventYear);
  if (empty($_GET["year"])){
  $eventYear = 2016;
  }
  
  $con = mysqli_connect(HOST,USER,PASS,DB) or die ("Database Connection Failed");
  
  $sql = "SELECT * FROM tableName";
  
  $res = mysqli_query($con,$sql);
  
  if (!$res) {
  printf("Error: %s\n", mysqli_error($con));
  exit();
  }
  
  $result = array();
  
  while($row = mysqli_fetch_array($res)){
  array_push($result,
  array('teamNumberLabel'=&gt;'Team Number',
  'teamNumber'=&gt;$row["teamNumber"],
  'teamEventLabel'=&gt;'Team Event Name',
  'teamEvent'=&gt;$row["teamEvent"],
  'teamDistrictCodeLabel'=&gt;'District Code: ',
  'teamDistrictCode'=&gt;$row["teamDistrictCode"],
  'teamCityLabel'=&gt;'City: ',
  'teamCity'=&gt;$row["teamCity"],
  'teamStateProvLabel'=&gt;'State/Province: ',
  'teamStateProv'=&gt;$row["teamStateProv"],
  'teamCountryLabel'=&gt;'Country: ',
  'teamCountry'=&gt;$row["teamCountry"],
  'teamNameFullLabel'=&gt;'Sponsors: ',
  'teamNameFull'=&gt;$row["teamNameFull"],
  'teamNameShortLabel'=&gt;'Nickname: ',
  'teamNameShort'=&gt;$row["teamNameShort"],
  'teamRobotNameLabel'=&gt;'Name: ',
  'teamRobotName'=&gt;$row["teamName"],
  'teamRookieYearLabel'=&gt;'Rookie Year: ',
  'teamRookieYear'=&gt;$row["teamRookieYear"],
  'teamWebsiteLabel'=&gt;'Website: ',
  'teamWebsite'=&gt;$row["teamWebsite"]
  ));
  }
  header('Content-Type: application/json');
  echo json_encode(array("result" =&gt; $result));
  
  mysqli_close($con);
  
  ?&gt; 
  </code></pre>
  
  <p>I have a lot of other files with similar code, but they all contain WHERE clauses on the SQL command, so it all works as expected. Just have the problem where nothing works without the WHERE clause included. I've tried placing quotes around the table name, but it shows incorrect SQL syntax, so that isn't it. Also read up on SQL commands and array_push and I can't seem to figure it out.</p>
  
  <p><strong>Update:</strong> As Marshall stated, I believe the issue now is data that is not in UTF-8, which causes the JSON encoding to fail and not display any data. The table is hundreds of entries long, so I'm going to filter out non UTF-8 characters before encoding to see if it works then.</p>
  
  <p><strong>Update 2:</strong> Found the issue. I have another script that runs through the list of teams for a single event (this one is similar but returns all teams for the entire year), and I went through the list until it failed similar to this one. A Canada event with non-UTF-8 characters is what's causing the scripts to fail. Montréal is showing as MontrÃ©al in the database and Québec as QuÃ©bec. The code worked earlier only because this event didn't exist when the code was initially tested, and the é is an unsupported character. This also explains why the code works with the WHERE clause and the array[] function, because it doesn't hit the malformed data in either case. Properly filtering the data coming in like I should've would have not caused this, but at least now I know the cause, I was really stuck on this one because the code looked correct and the SQL command was correct as well. Thanks for your help everyone.</p>
  
  <p><strong>Update 3:</strong> Okay so here's the full fix. I modified everything in PHPMyAdmin to the utf8mb4_unicode_ci collation, and utf8mb4 character set. Then modified the script that fetches the data from the API and enters it into the database. I'm using PDO to connect to the db, so I added the charset to the PDO entry.</p>
  
  <pre><code>$dbh = new PDO("mysql:host=localhost;dbname=dbname;charset=utf8mb4", 'username', 'password');
  </code></pre>
  
  <p>That got the data going into the database correctly, but the JSON parser still didn't work. Found out I also needed to explicitly tell it to work in the UTF-8MB4 charset. Adding</p>
  
  <pre><code>$con-&gt;set_charset("utf8mb4");
  </code></pre>
  
  <p>to the PHP script before the SQL query fixed that. Now the correct characters go through both where the data enters the database and when it is requested. So the problem was that the scripts were not set to UTF-8, when the data was coming through as such. Hopefully this helps someone with a similar problem.</p>