Здравствуйте!
Есть такой код
<?php
header('Content-Type:application/json');
require_once 'pdoconfig.php';
//if($_SERVER["CONTENT_TYPE"] == "application/json; charset=utf-8"){
$postData = file_get_contents('php://input');
var_dump($postData);
$data = json_decode($postData,true);
var_dump($data);
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$conn -> query("SET NAMES utf8");
// $conn->set_charset("utf8");
echo "Connected to $dbname at $host successfully.\n";
echo " type ={$_SERVER["CONTENT_TYPE"]}\n";
} catch (PDOException $pe) {
http_response_code(470);// int|bool;
die("Could not connect to the database $dbname :" . $pe->getMessage());
}
try{
$id=$data['id'];
$asp=$data['aspectRatio'];
$yie=$data['yields'];
$c_t_m=$data['cookTimeMinutes'];
$country = $data['country'];
$desc=$data['description'];
$p_t_m = $data['prepTimeMinutes'];
$t_t_m = $data['totalTimeMinutes'];
$name = $data['name'];
$t_url=$data['thumbnailUrl'];
echo "id= $id, asp=$asp,yel=$yie, ctm=$c_t_m,country=$country,desc=$desc,ptm=$p_t_m,ttm=$t_t_m,name=$name,url=$t_url\n";
$err = $conn -> query("INSERT INTO RECIPE(recipe_id,aspect_ratio,yields,cook_time_minutes,country,descriptions,prep_time_minutes,total_time_minutes,name,thumnai_url) VALUES('$id','$asp','$yie','$c_t_m','$country','$desc','$p_t_m','$t_t_m','$name','$t_url')");
echo "\nrec PDOStatement::errorCode(): ";
print $err->errorCode();
Водном случае отрабатывает нормально
I/okhttp.OkHttpClient: id= 8630, asp=9:16,yel=Порции: 1, ctm=20,country=США,desc=Если вам надоели .....,ptm=5,ttm=25,name=Овсяная смесь из теста для печенья с шоколадной крошкой,url=https://img.buzzfeed.com/thumbnailer-prod-us-east-1/video-api/assets/432886.jpg
I/okhttp.OkHttpClient:
I/okhttp.OkHttpClient: rec PDOStatement::errorCode(): 00000
В другом нет
I/okhttp.OkHttpClient: id= 8629, asp=9:16,yel=Порции: 1, ctm=10,country=США,desc=Каждый март McDonald's ......,ptm=5,ttm=25,name=Имитатор коктейля McDonald's Shamrock Shake,url=https://img.buzzfeed.com/thumbnailer-prod-us-east-1/video-api/assets/432796.jpg
I/okhttp.OkHttpClient:
I/okhttp.OkHttpClient: rec PDOStatement::errorCode():
В логах сервера во втором случае:
Backend fatal error: PHP Fatal error: Uncaught Error: Call to a member function errorCode() on bool in /home/ascer175/domains/androidyava.today/public_html/recipe_project/dbconnect.php:41\nStack trace:\n#0 {main}\n thrown in /home/ascer175/domains/androidyava.today/public_html/recipe_project/dbconnect.php on line 41\n
Вообще не понимаю как так?