PHP code example of nkey / caribu

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

    

nkey / caribu example snippets


    /* SuperDuperEntity.php */
    
    /**
     * @table super_duper_content
     */
    class SuperDuperEntity extends AbstractModel
    {
      /**
       * @column id
       */
      private $sid;
      
      private $content;
      
      public function setSid($sid)
      {
        $this->sid = $sid;
      }
      
      public function getSid()
      {
        return $this->sid;
      }
      
      public function setContent($content)
      {
        $this->content = $content;
      }
      
      public function getContent()
      {
        return $this->content;
      }
    }
  

    /* write-data-example.php */
    
    use \Nkey\Caribu\Orm\Orm;
    
    /* First configure the ORM */
    Orm::configure(array(
      'type' => 'sqlite',
      'file' => ':memory:'
    ));
    
    // Create sqlite database table for memory storage
    // Orm::getInstance()->getConnection()->exec("CREATE TABLE super_duper_content (id INTEGER PRIMARY KEY, content TEXT)");
    
    /* Now create a new entity and persist it to database */
    $entity = new SuperDuperEntity();
    $entity->setContent("Mega important content");
    $entity->persist();
  

    /* read-data-example.php */
    
    /* First read the entity from database */
    $entity = SuperDuperEntity::find(array('content' => "Mega important content"));
    
    /* Display the content */
    echo $entity->getContent();