If I try to update an entry in my database, it doesn't work, as in not update. But when I try to select a value from the same database, that works just fine. I'm not sure why this is so.
Update query:
$id = 1;
try {
$conn = db();
$sql = "UPDATE instagram SET token=?, expires=? WHERE id=$id";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
throw new Exception($conn->error);
}
mysqli_stmt_bind_param($stmt, "si", $tokenAccess, $tokenExpires);
mysqli_stmt_execute($stmt);
// on error
if (!mysqli_stmt_execute($stmt)) {
throw new Exception($conn->error);
}
var_dump($stmt);
$stmt->close();
$conn->close();
}
catch (Exception $e) {
print_r($e);
}
var_dump
for $stmt
returns:
object(mysqli_stmt)#4 (10) { ["affected_rows"]=> int(1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2) ["field_count"]=> int(0) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }
It's probably in plain sight and I'm missing the obvious. A pointer in the right direction is much appreciated.
UPDATE:
It has one entry where:
- token = ABCdefg123adc........ <-- example string, contains numbers and letters
- expires = 60
- created_at = 2019-12-01 08:57:26
- id = 1.
I tried to access the table via:
$sql = "INSERT INTO instagram (token, expires) VALUES (?, ?)";
This, like SELECT
, works.
I also found that if (!mysqli_stmt_execute($stmt))
was sending the entry twice, so I took that out. Still, updating the entry doesn't work.
I have also echoed the values for $tokenAccess
and $tokenExpires
. The result contains 60
for $tokenExpires
and the long-lived access token for $tokenAccess
, as expected.