tags:

views:

225

answers:

1

I am trying to save data into a database using PDO. All columns save correctly with the exception of one. No matter what I try, I cannot get the data to go in.

myfunc($db, $data) {

    echo $data; // <----- Outputs my data. example: 'jim jones'

    $stmt = $db->prepare("CALL test(:id, :data, :ip, :expires)");
    $stmt->bindParam(':id', $id, PDO::PARAM_STR);
    $stmt->bindParam(':data', $data, PDO::PARAM_STR);
    $stmt->bindParam(':ip', $ip, PDO::PARAM_STR);
    $stmt->bindParam(':expires', $expires, PDO::PARAM_STR);
    ...
}

So even after verifying that the data variable in fact holds my data, the bindParam method will not bind.

When I echo the data variable, I can see the data is there. It will not save though. If I copy the echo'd output of the data variable to screen and paste it into a new variable, it WILL save.

I'm at this now for a couple of hours. Can someone please have a look?


EDIT: I want to also mention that I have tried using bindValue() in place of bindParam() and the data for the data variable will still not save.

A: 

From the php docs for bindparam: *data_type*: Explicit data type for the parameter using the PDO::PARAM_* constants. To return an INOUT parameter from a stored procedure, use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter.

Example #3 Call a stored procedure with an INOUT parameter

/* Call a stored procedure with an INOUT parameter */
$colour = 'red';
$sth = $dbh->prepare('CALL puree_fruit(?)');
$sth->bindParam(1, $colour, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 12);
$sth->execute();
print("After pureeing fruit, the colour is: $colour");

PDO_PARAM_INPUT_OUTPUT is used when the param is passed into a stored procedure and could thus be changed after the sproc executes. The length parameter specifies the datatype's length and is only required when using PDO_PARAM_INPUT_OUTPUT

rkulla