Problems updating my SQLite db
Here is my PHP code:
<?php
require_once '../php-opencloud/lib/php-opencloud.php';
$database_config = require_once '../database.php';
$php_cloudconfig = require_once '../phpcloudconfig.php';
use OpenCloud\Rackspace;
try {
$conn = new PDO("sqlite:../sqlitedb");
function getCredentials($conn) {
$sql_get_credential = "SELECT * FROM rs_api_token WHERE id = 1";
$q = $conn->prepare($sql_get_credential);
$q->execute();
$cred = $q->fetch();
$new_cred['token'] = $cred['token'];
$new_cred['expiration'] = $cred['expiration'];
$new_cred['tenant'] = $cred['tenant'];
$new_cred['catalog'] = unserialize($cred['catalog']);
return $new_cred;
}
function setCredentials($conn, $token, $expiration, $tenant, $catalog) {
try {
$sql_insert = "UPDATE rs_api_token set token=:token,
expiration=:expiration, tenant=:tenant, catalog=:catalog WHERE
id = 1";
$q = $conn->prepare($sql_insert);
$q->execute(array(':token' => $token, ':expiration' =>
$expiration, ':tenant' => $tenant, ':catalog' =>
serialize($catalog)));
}
catch (Exception $e) {
die($e);
}
echo $token;
echo '<br>';
echo $expiration;
echo '<br>';
echo $tenant;
echo '<br>';
echo serialize($catalog);
echo '<br>';
die($q->queryString);
}
}
catch (PDOException $e)
{
die($e);
}
$connection = new
Rackspace('https://identity.api.rackspacecloud.com/v2.0/',
$php_cloudconfig['credentials']);
$credentials = getCredentials($conn);
$connection->ImportCredentials($credentials);
// Authenticate against the API to make sure your token is still valid
$connection->Authenticate();
// Compare result
$newCredentials = $connection->ExportCredentials();
if ($credentials['token'] != $newCredentials['token']) {
setCredentials($conn, $newCredentials['token'],
$newCredentials['expiration'], $newCredentials['tenant'],
$newCredentials['catalog']);
}
I am able to retrieve the information from my SQLite db, but I am unable
to update the content.
I am not getting any errors and when I echo the variables like you can see
in the code I get all the right values. It just does not update it. Could
it be, because on of my values is too big? If that's the case why is it
not telling me?
No comments:
Post a Comment