本文整理汇总了PHP中DboSource类的典型用法代码示例。如果您正苦于以下问题:PHP DboSource类的具体用法?PHP DboSource怎么用?PHP DboSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DboSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public function add()
{
//var_dump($this->request->data);
$this->loadModel('User');
$us = $this->User->find('all');
//var_dump($us['0']);
if (!empty($this->data)) {
$this->loadModel('User');
$this->User->create();
//$this->request->data['User']['ip'] = $this->request->clientIp();
$m = $this->request->data['User']['dob']['month'];
$d = $this->request->data['User']['dob']['day'];
$y = $this->request->data['User']['dob']['year'];
$dob = $m . '-' . $d . '-' . $y;
//$mem = $this->request->data['User']['member'];
//var_dump($mem);
$this->request->data['User']['dob'] = $dob;
//$this->request->data['User']['mem'] = 'User';
//$this->request->data['login_attempt']['login_times'] = 1;
$this->request->data['User']['register_date'] = DboSource::expression('NOW()');
if ($this->User->save($this->request->data)) {
//echo "<div id='footer_a_link'>";
$this->Session->setFlash('You are registered successfully. Please log in.');
// $this->redirect(array('action' => 'login', 'controller' => 'Users'));
} else {
$this->Session->setFlash('Not Registered');
}
}
}
示例2: create_concert
public function create_concert()
{
$this->loadModel('Taste');
$load_taste = $this->Taste->find('all');
$this->set(compact('load_taste', 'load_taste'));
//var_dump($this->request->data);
$this->loadModel('Band');
$load_band = $this->Band->find('all');
$this->set(compact('load_band', 'load_band'));
$this->loadModel('Concert');
//var_dump($this->request->data);
if (!empty($this->data)) {
$this->Concert->create();
//$this->request->data['User']['ip'] = $this->request->clientIp();
$this->request->data['Concert']['concert_name'] = $this->request->data['Concerts']['concert_name'];
$this->request->data['Concert']['concert_place'] = $this->request->data['Concerts']['concert_place'];
$this->request->data['Concert']['concert_time'] = $this->request->data['Concerts']['concert_time'];
$this->request->data['Concert']['concert_ticket_price'] = $this->request->data['Concerts']['concert_ticket_price'];
$this->request->data['Concert']['concert_band'] = $this->request->data['concert_band'] + 1;
$this->request->data['Concert']['concert_taste'] = $this->request->data['concert_taste'] + 1;
//$this->request->data['Concert']['band_name'] = $this->request->data['Bands']['band_name'];
//$this->request->data['login_attempt']['login_times'] = 1;
$this->request->data['Concert']['concert_creation_date'] = DboSource::expression('NOW()');
if ($this->Concert->save($this->request->data)) {
//echo "<div id='footer_a_link'>";
$this->Session->setFlash('Concert has been registered successfully.');
//$this->redirect(array('action' => 'index', 'controller' => 'Bands'));
} else {
$this->Session->setFlash('Not Registered');
}
}
}
示例3: process
public function process()
{
$c = new CakeEmail('default');
//grab 50 emails
$emails = $this->EmailMessage->find("all", array("conditions" => array("EmailMessage.processed" => 0, "EmailMessage.to !=" => '', "NOT" => array("EmailMessage.to" => null)), "contain" => array()));
$total_emails = count($emails);
$this->out("emails to processes: " . $total_emails);
SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Emails to processes: " . $total_emails));
foreach ($emails as $email) {
$e = $email['EmailMessage'];
$c->reset();
$c->config('default');
$c->to($e['to']);
$c->subject($e['subject']);
$c->template($e['template']);
$c->viewVars(array("msg" => $email));
if ($c->send()) {
$this->EmailMessage->create();
$this->EmailMessage->id = $e['id'];
$this->EmailMessage->save(array("processed" => 1, "sent_date" => DboSource::expression('NOW()')));
$total_emails--;
$this->out("Email:" . $e['to'] . " Template: " . $e['template']);
} else {
$this->out("Email failed: " . $e['id']);
SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Email Failed: " . $e['id']));
}
}
}
示例4: delete
public function delete($id = null)
{
if (!$id) {
$this->Session - setFlash('Tarea inválida');
$this->redirect(array('action' => 'index', 'pendiente'), null, true);
}
$this->Tarea->id = $id;
$this->request->data['Tarea']['estado'] = 1;
$this->request->data['Tarea']['finalizado'] = DboSource::expression('NOW()');
if ($this->Tarea->save($this->request->data)) {
$this->Session->setFlash('Tarea #' . $id . ' Terminada');
$this->redirect(array('action' => 'index', 'pendiente'), null, true);
}
}
示例5: beforeSave
public function beforeSave($options = array())
{
$key = $this->alias;
$update_time = @DboSource::expression('NOW()');
//update columns
if (empty($this->id)) {
if (empty($this->data[$key]['created'])) {
$this->data[$key]['created'] = $update_time;
}
}
if (empty($this->data[$key]['modified'])) {
$this->data[$key]['modified'] = $update_time;
}
return true;
}
示例6: admin_add
function admin_add()
{
if (!empty($this->request->data) && $this->request->is('post')) {
$this->User->create();
$this->request->data['User']['user_added_date'] = @DboSource::expression('NOW()');
$this->request->data['User']['password'] = md5($this->request->data['User']['password']);
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user added successfully', true), 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.', true), 'default', array('class' => 'error'));
}
}
$roles = $this->UserRole->find('all', array('conditions' => array('status' => 'Active'), 'order' => array('role_name' => 'asc')));
$this->set('Roles', $roles);
}
示例7: admin_edit
public function admin_edit($id = null)
{
$this->Cmse->id = $id;
if (!$this->Cmse->exists()) {
throw new NotFoundException(__('Invalid Page'));
}
if ($this->request->is('post') || $this->request->is('put')) {
$this->request->data['Cmse']['page_modified_date'] = DboSource::expression('now()');
if ($this->Cmse->save($this->request->data)) {
$this->Session->setFlash(__('The page has been saved'), 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The page could not be saved. Please, try again.'), 'default', array('class' => 'error'));
}
} else {
$this->request->data = $this->Cmse->read(null, $id);
}
}
示例8: assignUserACoupon
public function assignUserACoupon($forUser, $couponType = 1, $parameters = [])
{
$fields = ['presenter_id' => null, 'start_date' => date('Y-m-d H:i:s'), 'end_date' => '0000-00-00 00:00:00', 'max_redemptions' => '-1', 'discount_percentage' => 50, 'discount_flat' => '0.00', 'discount_sku' => null, 'reference_id' => null, 'user_visible' => true, 'expiration_date' => DboSource::expression('DATE_ADD(NOW(),INTERVAL 1 YEAR)')];
$data = array_merge($fields, $parameters);
$coupon = $this->CouponPresenter->getPresenterCoupon($data['presenter_id'], $couponType);
if (empty($coupon)) {
$success = $this->CouponPresenter->saveCreate(array("presenter_id" => $data['presenter_id'], "coupon_id" => $couponType, "start_date" => $data['start_date'], "end_date" => $data['end_date'], "max_redemptions" => $data['max_redemptions'], "discount_percentage" => $data['discount_percentage'], "discount_flat" => $data['discount_flat'], "discount_sku" => $data['discount_sku'], "expiration_date" => $data['expiration_date']));
if ($success) {
$coupon = $this->CouponPresenter->getPresenterCoupon($data['presenter_id'], $couponType);
}
}
//Coupon should be assigned now
if (!empty($coupon)) {
$this->create();
$return = $this->save(array("coupon_presenter_id" => $coupon['CouponPresenter']['id'], "user_id" => $forUser, "reference_id" => $data['reference_id'], "user_visible" => $data['user_visible'], "date_added" => date('Y-m-d H:i:s'), "redemption_reference_id" => '', "redemption_amount" => '0.00', "expiration_date" => $data['expiration_date']));
} else {
$return = NULL;
}
return $return;
}
示例9: testRealQueries
/**
* testRealQueries method
*
* @access public
* @return void
*/
public function testRealQueries()
{
$this->loadFixtures('Apple', 'Article', 'User', 'Comment', 'Tag', 'Sample', 'ArticlesTag');
$Apple = ClassRegistry::init('Apple');
$Article = ClassRegistry::init('Article');
$result = $this->Dbo->rawQuery('SELECT color, name FROM ' . $this->Dbo->fullTableName('apples'));
$this->assertTrue(!empty($result));
$result = $this->Dbo->fetchRow($result);
$expected = array($this->Dbo->fullTableName('apples', false) => array('color' => 'Red 1', 'name' => 'Red Apple 1'));
$this->assertEqual($expected, $result);
$result = $this->Dbo->fetchAll('SELECT name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id');
$expected = array(array($this->Dbo->fullTableName('apples', false) => array('name' => 'Red Apple 1')), array($this->Dbo->fullTableName('apples', false) => array('name' => 'Bright Red Apple')), array($this->Dbo->fullTableName('apples', false) => array('name' => 'green blue')), array($this->Dbo->fullTableName('apples', false) => array('name' => 'Test Name')), array($this->Dbo->fullTableName('apples', false) => array('name' => 'Blue Green')), array($this->Dbo->fullTableName('apples', false) => array('name' => 'My new apple')), array($this->Dbo->fullTableName('apples', false) => array('name' => 'Some odd color')));
$this->assertEqual($expected, $result);
$result = $this->Dbo->field($this->Dbo->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id');
$expected = array('color' => 'Red 1', 'name' => 'Red Apple 1');
$this->assertEqual($expected, $result);
$Apple->unbindModel(array(), false);
$result = $this->Dbo->read($Apple, array('fields' => array($Apple->escapeField('name')), 'conditions' => null, 'recursive' => -1));
$expected = array(array('Apple' => array('name' => 'Red Apple 1')), array('Apple' => array('name' => 'Bright Red Apple')), array('Apple' => array('name' => 'green blue')), array('Apple' => array('name' => 'Test Name')), array('Apple' => array('name' => 'Blue Green')), array('Apple' => array('name' => 'My new apple')), array('Apple' => array('name' => 'Some odd color')));
$this->assertEqual($expected, $result);
$result = $this->Dbo->read($Article, array('fields' => array('id', 'user_id', 'title'), 'conditions' => null, 'recursive' => 1));
$this->assertTrue(Set::matches('/Article[id=1]', $result));
$this->assertTrue(Set::matches('/Comment[id=1]', $result));
$this->assertTrue(Set::matches('/Comment[id=2]', $result));
$this->assertFalse(Set::matches('/Comment[id=10]', $result));
}
示例10: testIsConnected
/**
* Test isConnected
*
* @return void
*/
public function testIsConnected()
{
$this->Dbo->disconnect();
$this->assertFalse($this->Dbo->isConnected(), 'Not connected now.');
$this->Dbo->connect();
$this->assertTrue($this->Dbo->isConnected(), 'Should be connected.');
}
示例11: testRenameField
/**
* TestRenameField method
*
* @return void
*/
public function testRenameField()
{
$this->loadFixtures('User', 'Post');
$Model = new Model(array('table' => 'posts', 'ds' => 'test'));
$Migration = new TestPrecheckCakeMigration(array('up' => array('rename_field' => array('posts' => array('updated' => 'renamed_updated'))), 'down' => array('rename_field' => array('posts' => array('renamed_updated' => 'updated'))), 'precheck' => 'Migrations.PrecheckCondition'));
$Migration->initDb();
$fields = $this->db->describe($Model);
$this->assertTrue(isset($fields['updated']));
$this->assertFalse(isset($fields['renamed_updated']));
$this->assertTrue($Migration->Precheck->beforeAction($Migration, 'rename_field', array('table' => $this->db->fullTableName('posts', false, false), 'old_name' => 'updated', 'new_name' => 'renamed_updated')));
$this->assertTrue($Migration->run('up'));
$fields = $this->db->describe($Model);
$this->assertFalse(isset($fields['updated']));
$this->assertTrue(isset($fields['renamed_updated']));
$this->assertFalse($Migration->Precheck->beforeAction($Migration, 'rename_field', array('table' => $this->db->fullTableName('posts', false, false), 'old_name' => 'updated', 'new_name' => 'renamed_updated')));
$this->assertTrue($Migration->Precheck->beforeAction($Migration, 'rename_field', array('table' => $this->db->fullTableName('posts', false, false), 'old_name' => 'renamed_updated', 'new_name' => 'updated')));
try {
$Migration->run('up');
} catch (MigrationException $e) {
$this->fail('Exception triggered ' . $e->getMessage());
}
$this->assertTrue($Migration->run('down'));
$fields = $this->db->describe($Model);
$this->assertTrue(isset($fields['updated']));
$this->assertFalse(isset($fields['renamed_updated']));
$this->assertTrue($Migration->Precheck->beforeAction($Migration, 'rename_field', array('table' => $this->db->fullTableName('posts', false, false), 'old_name' => 'updated', 'new_name' => 'renamed_updated')));
$this->assertFalse($Migration->Precheck->beforeAction($Migration, 'rename_field', array('table' => $this->db->fullTableName('posts', false, false), 'old_name' => 'renamed_updated', 'new_name' => 'updated')));
try {
$Migration->run('down');
} catch (MigrationException $e) {
$this->fail('Exception triggered ' . $e->getMessage());
}
}
示例12: testDescribeWithUuidPrimaryKey
/**
* test that describe does not corrupt UUID primary keys
*
* @return void
*/
public function testDescribeWithUuidPrimaryKey() {
$tableName = 'uuid_tests';
$this->Dbo->query("CREATE TABLE {$tableName} (id VARCHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME)");
$Model = new Model(array('name' => 'UuidTest', 'ds' => 'test', 'table' => 'uuid_tests'));
$result = $this->Dbo->describe($Model);
$expected = array(
'type' => 'string',
'length' => 36,
'null' => false,
'default' => null,
'key' => 'primary',
);
$this->assertEqual($result['id'], $expected);
$this->Dbo->query('DROP TABLE ' . $tableName);
$tableName = 'uuid_tests';
$this->Dbo->query("CREATE TABLE {$tableName} (id CHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME)");
$Model = new Model(array('name' => 'UuidTest', 'ds' => 'test', 'table' => 'uuid_tests'));
$result = $this->Dbo->describe($Model);
$expected = array(
'type' => 'string',
'length' => 36,
'null' => false,
'default' => null,
'key' => 'primary',
);
$this->assertEqual($result['id'], $expected);
$this->Dbo->query('DROP TABLE ' . $tableName);
}
示例13: testNestedTransaction
/**
* Test nested transaction
*
* @return void
*/
public function testNestedTransaction()
{
$nested = $this->Dbo->useNestedTransactions;
$this->Dbo->useNestedTransactions = true;
if ($this->Dbo->nestedTransactionSupported() === false) {
$this->Dbo->useNestedTransactions = $nested;
$this->skipIf(true, 'The MySQL server do not support nested transaction');
}
$this->loadFixtures('Inno');
$model = ClassRegistry::init('Inno');
$model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
$model->cacheQueries = false;
$this->Dbo->cacheMethods = false;
$this->assertTrue($this->Dbo->begin());
$this->assertNotEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->begin());
$this->assertTrue($model->delete(1));
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->commit());
$this->assertEmpty($model->read(null, 1));
$this->assertTrue($this->Dbo->rollback());
$this->assertNotEmpty($model->read(null, 1));
$this->Dbo->useNestedTransactions = $nested;
}
示例14: testSetValue
/**
* Test that value() quotes set values even when numeric.
*
* @return void
*/
public function testSetValue()
{
$column = "set('a','b','c')";
$result = $this->Dbo->value('1', $column);
$this->assertEquals("'1'", $result);
$result = $this->Dbo->value(1, $column);
$this->assertEquals("'1'", $result);
$result = $this->Dbo->value('a', $column);
$this->assertEquals("'a'", $result);
}
示例15: testFetchRowColumnParsing
/**
* Test that fields are parsed out in a reasonable fashion.
*
* @return void
*/
public function testFetchRowColumnParsing()
{
$this->loadFixtures('User');
$sql = 'SELECT "User"."id", "User"."user", "User"."password", "User"."created", (1 + 1) AS "two" ' . 'FROM "users" AS "User" WHERE ' . '"User"."id" IN (SELECT MAX("id") FROM "users") ' . 'OR "User.id" IN (5, 6, 7, 8)';
$result = $this->Dbo->fetchRow($sql);
$expected = array('User' => array('id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23'), 0 => array('two' => 2));
$this->assertEquals($expected, $result);
$sql = 'SELECT "User"."id", "User"."user" ' . 'FROM "users" AS "User" WHERE "User"."id" = 4 ' . 'UNION ' . 'SELECT "User"."id", "User"."user" ' . 'FROM "users" AS "User" WHERE "User"."id" = 3';
$result = $this->Dbo->fetchRow($sql);
$expected = array('User' => array('id' => 3, 'user' => 'larry'));
$this->assertEquals($expected, $result);
}