MySQL Forums
Forum List  »  PHP

insert json into mysql from url with PHP
Posted by: Miguel Rodriguez
Date: March 11, 2022 12:58AM

newbie with mysql and even more with PHP
I've tried to rely on PHP for this operation and I think I can't find the right format....
I put the code and the error it throws.

surely you will quickly see the correction.



<?php

$host="HOST";
$port=3306;
$user="USER";
$password="PASS";
$dbname="DB";

$con = new mysqli($host, $user, $password, $dbname, $port)
or die ('Could not connect to the database server' . mysqli_connect_error());

$url = 'https://unaAPI';;
$json = file_get_contents($url);
//$json = mb_convert_encoding($json, 'UTF-8', "ISO-8859-1");


if ($stmt = $con->prepare("INSERT INTO db.table (field1) VALUES ( $json )")) {
$stmt->execute();
}

$stmt->close();

$con->close();
?>



Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"DATO":


in line 16, ... if ($stmt = $con->prepare("INSERT INTO ...


Thanks in advance

Options: ReplyQuote


Subject
Written By
Posted
insert json into mysql from url with PHP
March 11, 2022 12:58AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.