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.
}}

//Query object
$user = UserTable::findOneByPK(1);
var_dump($user);

//Change the object
$user->name = 'Jack';
$user->save();

//Add new object
$user = new UserTable();
$user->name = 'Michel';
$user->save();
echo $user->id;



//Create database configuration
$cfg = new MySQL([
			'host'=>'localhost',
			'user'=>'root',
			'password'=>'123456',
			'database'=>'database'
		]);

//Create a database link instance
$ins = DBAbstract::instance($config);

//Create a query object (query statement)
$query = (new Query())->select()->field('id', 'title')->from('blog_article');

//Get the results
$ret = $ins->getPage($query);

//Get the count
$count = $ins->getCount($query);


//Create database configuration
$cfg = new MySQL([
			'host'=>'localhost',
			'user'=>'root',
			'password'=>'123456',
			'database'=>'database',
'max_reconnect_count' => 10, //Set the maximum number of reconnections
		]);
$ins = DBAbstract::instance($config);
//...