public function allowTemporaryLogin($userId, $email, $expirationTime = '+1 hour') { $token = Basic::randomizer(80); dibi::insert(self::TEMPORARY_LOGIN_TABLE, array('users_id' => $userId, 'email' => $email, 'token' => $token, 'expire' => dibi::datetime(strtotime($expirationTime))))->execute(); return $token; }
public function insert($data) { $this->cleanData($data); $data['created'] = dibi::datetime(); $data['ip'] = $_SERVER['REMOTE_ADDR']; return dibi::query('INSERT INTO [guestbook]', $data); }
<style> pre.dibi { padding-bottom: 10px; } </style> <h1>dibi SQL builder example</h1> <pre> <?php require_once 'Nette/Debug.php'; require_once '../dibi/dibi.php'; date_default_timezone_set('Europe/Prague'); dibi::connect(array('driver' => 'sqlite', 'database' => 'sample.sdb')); // dibi detects INSERT or REPLACE command dibi::test(' REPLACE INTO [products]', array('title' => 'Super product', 'price' => 318, 'active' => TRUE)); // -> REPLACE INTO [products] ([title], [price], [active]) VALUES ('Super product', 318, 1) // multiple INSERT command $array = array('title' => 'Super Product', 'price' => 12, 'brand' => NULL, 'created' => dibi::datetime()); dibi::test("INSERT INTO [products]", $array, $array, $array); // -> INSERT INTO [products] ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...) // dibi detects UPDATE command dibi::test("\n\tUPDATE [colors] SET", array('color' => 'blue', 'order' => 12), "\n\tWHERE [id]=%i", 123); // -> UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123 // SELECT $ipMask = '192.168.%'; $timestamp = mktime(0, 0, 0, 10, 13, 1997); dibi::test(' SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE %s', $ipMask, ' AND [date] > ', dibi::date($timestamp)); // -> SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE '192.168.%' AND [date] > 876693600 // IN array