PHP code example of uzulla / cfedb2

1. Go to this page and download the library: Download uzulla/cfedb2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

uzulla / cfedb2 example snippets


$post = new Post();
$post->val('text', 'this is text');
$post->val('num', 123);
$post->saveItem();

$post2 = Post::getById(1);
echo $post2->val('text');

$post3 = Post::getBySome('text', 'this is text');
if(empty($post3)){
    echo "not found";
}

$post_list = Post::getsBySQL('SELECT * FROM post WHERE id>:id', array('id'=>5));
if(empty($post_list)){
    echo "not found";
}
foreach($post_list as $p){
    echo $p->val('id');
}

$post->deleteItem();

//もし貴方がROWオブジェクト嫌いなら…

$post_list = Post::getsHashBySome('text', 'this is text');



s Post extends \Uzulla\CFEDb2{
    static $tablename = 'post';
    static $pkeyname = 'id';
    public function __construct() {
        $this->values['id'] = null;
        $this->values['text'] = null;
        $this->values['num'] = null;
        $this->values['created_at'] = null;
        $this->values['updated_at'] = null;
    }
    public function as_you_like(){
        return $this->val('id').' as you like!';
    }
    static function getMySpecial(){
        return static::getById(3);
    }
}

\Uzulla\CFEDb2::$config = array(
    'type'=> 'mysql',
    // 'type'=> 'sqlite',
    'dsn' => 'host=127.0.0.1;dbname=test;charset=utf8mb4',
    // 'dsn' => 'unix_socket=/tmp/mysql.sock;dbname=test',
    // 'dsn' => __DIR__.'/sqlite.db',
    'user' => "",
    'pass' => "",
    'pre_exec' => false,
    'reuse_pdo' => true,
    'DEBUG_BACKTRACE' => true, // or false, enable backtrace log.
    'log'=> null // null will use error_log, Psr-3 logger instance(ex:monolog)
);