Can’t send a post request when the ‘Content-Type’ is set to ‘application/json’

It turns out that CORS only allows some specific content types. The only allowed values for the Content-Type header are: application/x-www-form-urlencoded multipart/form-data text/plain Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS To set the content type to be ‘application/json’, I had to set a custom content type header in the API. Just removed the last header and added this one: ->header(‘Access-Control-Allow-Headers’, … Read more

mysql_fetch_array return only one row

That’s because the array represents a single row in the returned result set. You need to execute the mysql_fetch_array() function again to get the next record. Example: while($data = mysql_fetch_array($array)) { //will output all data on each loop. var_dump($data); }

Trying to get property of non-object in [duplicate]

Check the manual for mysql_fetch_object(). It returns an object, not an array of objects. I’m guessing you want something like this $results = mysql_query(“SELECT * FROM sidemenu WHERE `menu_id`='”.$menu.”‘ ORDER BY `id` ASC LIMIT 1″, $con); $sidemenus = array(); while ($sidemenu = mysql_fetch_object($results)) { $sidemenus[] = $sidemenu; } Might I suggest you have a look … Read more

PDO::fetchAll vs. PDO::fetch in a loop

Little benchmark with 200k random records. As expected, the fetchAll method is faster but require more memory. Result : fetchAll : 0.35965991020203s, 100249408b fetch : 0.39197015762329s, 440b The benchmark code used : <?php // First benchmark : speed $dbh = new PDO(‘mysql:dbname=testage;dbhost=localhost’, ‘root’, ”); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql=”SELECT * FROM test_table WHERE 1″; $stmt = $dbh->query($sql); … Read more