<?php use Onephile\Model; $Model = Model::make('model_test_1'); $results = $Model->select(array('where' => "`email`='%s' OR id=%d", 'args' => array('*****@*****.**', 3))); // expecting result as array foreach ($results as $v) { // fmt() runs value thru htmlentities by default (& => &); echo implode("\n", array('ID: ' . $v->fmt('id'), 'Name: ' . $v->fmt('name'), 'Email: ' . $v->fmt('email'))) . "\n\n"; }
<?php use Onephile\Model; Model::printDebug();
<?php use Onephile\Model; $ModelWithId = Model::make('model_test_1', $new_id); var_dump($ModelWithId->id); var_dump($ModelWithId->name);
<?php use Onephile\Model; $result = Model::make('model_test_1')->insertArray(array(array('name' => 'Example & Sons', 'email' => '*****@*****.**'), array('name' => 'Example & Sons, Inc.', 'email' => '*****@*****.**'), array('name' => 'Another Company', 'email' => '*****@*****.**'))); var_dump($result);
<?php use Onephile\Model; //----------------------------------------------------- // configure access to database //----------------------------------------------------- Model::configure(array('DB_NAME' => DB_NAME, 'DB_USER' => DB_USER, 'DB_PASS' => DB_PASS, 'DB_HOST' => DB_HOST, 'DB_CHARSET' => 'utf8', 'DEBUG' => true)); // make sure we start with an empty table Model::truncateTable('model_test_1');
<?php use Onephile\Model; Model::configure(array('DB_NAME' => DB_NAME, 'DB_USER' => DB_USER, 'DB_PASS' => DB_PASS, 'DB_HOST' => DB_HOST, 'DB_CHARSET' => 'utf8', 'DEBUG' => true)); var_dump(Model::getConfig('DB_CHARSET'));
/** * update */ public function testUpdate() { $data = array('name' => 'new name 1'); // no id sent to update $Test = Model::make(self::$table1); $r = $Test->update($data); $this->assertFalse($r); // id sent $id = 1; $r = $Test->update($data, $id); $this->assertEquals($id, $r); // load model with $id $Test = Model::make(self::$table1, $id); $r = $Test->update($data); $this->assertEquals($id, $r); // update again with refresh on model $data['name'] = 'new name one'; $r = $Test->update($data, true); $this->assertEquals($id, $r); $this->assertEquals($data['name'], $Test->val('name')); }
<?php use Onephile\Model; try { Model::createTable('model_test_1', array('id' => array('type' => 'int', 'length' => '11', 'not_null' => true, 'key' => 'PRI', 'auto_increment' => true), 'name' => array('type' => 'varchar', 'length' => '255', 'default' => null), 'email' => array('type' => 'varchar', 'length' => '255', 'key' => 'UNI'), 'price' => array('type' => 'double', 'length' => '8,2'), 'description' => array('type' => 'text'), 'created' => array('type' => 'int', 'length' => '10'), 'modified' => array('type' => 'int', 'length' => '10'))); } catch (Exception $e) { die("Error: " . $e); } echo 'Success!';