Error in PHP webservice

0

I am using SOAP library web service for Android. I have this web service.

function ws_put_q_answers($ids, $date, $users, $completeds, $idstores, $checkins, $checkouts, $locations) 
{

    include "conn.php"; 
    for($i = 0; $i < sizeof($ids); $i++){
        $id = $ids[$i];
        $date = $date;
        $user = $users[$i];
        $completed = $completeds[$i];
        //$noReplies = $nosReplies[$i];
        $idstore = $idstores[$i];
        $checkin = $checkins[$i];
        $checkout = $checkouts[$i];
        $location = $locations[$i];

        $sql = "INSERT INTO q_answers([id_questionnarie], [date], [user], [completed], [noReplies], [id_store], [checkin], [checkout], [location])
            VALUES (". $id .", '" . $date . "', '". $user . "', ". $completed .  ", 0, " . $idstore . ", '" . $checkin . "', '" . $checkout . "', '" . $location . "')";
        //$sql = "INSERT INTO q_answers([id_questionnarie], [date], [user], [completed], [noReplies], [id_tienda], [checkin], [checkout])
            //VALUES (". $id .", '" . $date . "', '". $user . "', ". $completed .  ", 0, " . $idstore . ", '" . $checkin . "', '" . $checkout . "')";

        $query = $db->prepare($sql);
        $query->execute(); 

    }                                                 

    if (!$db) {
        die('ERROR.. No se logro la conexion con la BD TFBO');
        return(0);
    }  
    else {
        //$processReturn =  $val0; 
        return(1);
    }
}

The problem is that sometimes (VERY RARE IN the "checkout" column) it inserts the word "Array" as such.

All the parameters that I send are Arrangements, I go through them and I save temporary variables.

Any idea why this happens sometimes?

    
asked by Oshcar 14.02.2017 в 00:02
source

1 answer

0

The insertion statement, as you have it, forces the conversion of the data types to string.

If one of the values you are inserting is an array (nested within the array you are traversing), it will insert the result of the conversion from an array to string, which is precisely Array .

Forcing this conversion throws an error of type NOTICE. If you check the logs, and you have a login level that captures the notices, you should see them:

PHP Notice:  Array to string conversion in...

To discard this implicit conversion from array to string, it would be best to use the same prepared statement that you have, but with bindParam

$sql = "insert into tabla (id, val1, val2) values (:id, :val1, :val2)";
$query = $conn->prepare($sql);

$query->bindParam(':id', $id, \PDO::PARAM_INT);
$query->bindParam(':val1', $val1, \PDO::PARAM_STR);
$query->bindParam(':val2', $val2, \PDO::PARAM_STR);

$query->execute();
    
answered by 14.02.2017 в 00:17