MySQL Forums
Forum List  »  PHP

Re: Update mySQL row with PHP using sproc
Posted by: Arthur Chan
Date: June 10, 2020 10:27PM

mysqli multi_query works, but not what I have expected. Please look at my example, it is as simple as I can render the underlying problem.

I was hoping @flag would return true if connected and updated row, else return false.

Also, when I try to json_encode($response) the array and run the PHP in Firefox, it returns this error:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

header("Content-type:application/json; charset=UTF-8");
$conn = mysqli_connect("localhost", "usr", "pwd", "instance");
mysqli_set_charset( $conn, "utf8mb4" );
if (mysqli_connect_errno($conn)) {
   echo "Failed to connect to MySQL: " .mysqli_connect_error();
$personId = $_REQUEST['personId'];
$pAddrL1  = $_REQUEST['pAddrL1'];
$result = $conn->multi_query("CALL sp_updCompany('$personId','$pAddrL1', @flag); SELECT @flag");

if($result==1) {
    echo('Updated data flag = '.$result);
    $response = ["flag"=>$result];
    echo json_encode ($response);
} else {
    $response = ["flag" =>-1];
    echo json_encode ($response);


Options: ReplyQuote

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.