By nicodv on
Again, my db skills and php are not enough... any idea what i'm doing so bad? Thanks
ERROR: Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2095 of /Applications/MAMP/htdocs/drupal/includes/database/database.inc)
My query:
function connected_since_time() {
// get the timestamp of the user's last connection
// use database api to retrieve the user's actual session's connection time
global $user;
$timestamp = db_query("SELECT timestamp FROM {sessions} WHERE uid = :uid",
array(':uid' => $user))->fetchField();
}
PS: i want it to give me back the timestamp... just that
1000 thanks
Comments
You're passing the whole user
You're passing the whole user object, not just their UID.
thanks, but now...
...now i discover that is the next part of this code that doesnt show me the timestamp from the table. Sorry to bother you, but do you see also the problem in the next block of code?
function connected_since_time() {
global $user;
// get the timestamp of the user's last connection
// use database api to retrieve the user's actual session's connection time
$timestamp = db_query("SELECT timestamp FROM {sessions} WHERE uid = :uid",
array(':uid' => $user->uid))->fetchField();
}
/**
* implements hook_block_view()
* shows the title of the block (subject) and the content to be shown
*/
function connected_since_block_view($delta = '') {
switch ($delta){
case 'connected_since':
$block['subject'] = t('You have been connected since');
if(user_access('administer blocks')){
//retrieve and process data here and identify request source as block
// now lets save the data in a vble, we use the custom function to do it
$result = connected_since_time();
}
if(empty($result)) { // no timestamp found,... would be weird but...
$block['content'] = t('We couldnt find your timestamp, sorry');
}
else {
//show the time of connection
$block['content'] = $result;
}
}
return $block;
thanks a lot
THE VERY LITTLE AGENCY
never mind, solved it!
Thanks to you, but i just noticed that i didnt return the value retrieved, so (in case someone as newbie as me is interested) the code is:
function connected_since_time() {
global $user;
// get the timestamp of the user's last connection
// use database api to retrieve the user's actual session's connection time
$timestamp = db_query("SELECT timestamp FROM {sessions} WHERE uid = :uid",
array(':uid' => $user->uid))->fetchField();
return $timestamp;
}
THE VERY LITTLE AGENCY