Jump to content

How to do this with PDO?


3raser

Recommended Posts

I don't have too much experience with PDO, but I want to remove all inactive users from online_users WHERE time() - time (table) > 480

 

$this->database->processQuery("DELETE FROM `online_users` WHERE ". time() ." - `time` > 480", array(), false);

 

I receive this error statement:

 

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\wamp\www\OSREMAKE\structure\database.php on line 55

 

So which part requires the token?  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/264474-how-to-do-this-with-pdo/
Share on other sites

Just FYI - always a bad idea to "DELETE" in a web application.

 

A better design for your system would be to have a table called  `sessions` (instead of `online_users`).

 

In sessions, store the user id, (php session id if you want) and time created.

 

To get `online_users`, just do "SELECT * FROM `sessions` WHERE `created` > NOW() - INTERVAL 8 MINUTE;"

 

To make it speedier, make `created` a clustered index.

 

By storing sessions indefinitely, you can also generate reports of user activity, know when people logged in last, how often they log in, etc.

 

And you never have to delete anything.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.