PHP code example of lfphp / porm

1. Go to this page and download the library: Download lfphp/porm 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/ */

    

lfphp / porm example snippets



use LFPhp\PORM\ORM\Model;

class User extends Model {

static public function getTableName(){
 // TODO: Implement getTableName() method.
}

static public function getAttributes(){
 // TODO: Implement getAttributes() method.
}

static protected function getDBConfig($operate_type = self::OP_READ){
 // TODO: Implement getDBConfig() method.
}}

//查询对象 
$user = UserTable::findOneByPK(1);
var_dump($user);

//更改对象
$user->name = 'Jack';
$user->save();

//新增对象
$user = new UserTable();
$user->name = 'Michel';
$user->save();
echo $user->id;



//创建数据库配置
$cfg =  new MySQL([
			'host'=>'localhost',
			'user'=>'root',
			'password'=>'123456',
			'database'=>'database'
		]);

//创建数据库链接实例
$ins = DBAbstract::instance($config);

//创建查询对象(查询语句)
$query = (new Query())->select()->field('id', 'title')->from('blog_article');

//获取结果
$ret = $ins->getPage($query);

//获取计数
$count = $ins->getCount($query);


//创建数据库配置
$cfg =  new MySQL([
			'host'=>'localhost',
			'user'=>'root',
			'password'=>'123456',
			'database'=>'database',
            'max_reconnect_count' => 10, //设置最大重连次数   
		]);
$ins = DBAbstract::instance($config);
//...