php - Array to string conversion error with json_encode -
i have connect function mysql database so:
function connect() { $config = parse_ini_file('../../config.ini'); // try , connect database self::$conn = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']); //check if both bools , false === checks type , equality if(self::$conn === false) { header("http/1.1 500 internal server error"); header("content-type: application/json"); $response = array("response"=>"failed connect database"); echo "json_encode($response)"; die(); } }
i having issue when json_encode (for fail connection). error : notice: array string conversion in /var/www/html/somesite.co/public_html/api/index.php on line 47
json_encode(array)
really have no idea why i'm getting error. have encoded , echo'd , array before no issues. give me pointers might doing wrong please?
you getting error trying echo
array
. , don't wrap function call in quotes.
replace
echo "json_encode($response)";
with
echo json_encode($response);
Comments
Post a Comment