PHP code example of apsxj / mysql

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

    

apsxj / mysql example snippets


// For example, from the root directory...



class Connection extends \apsxj\mysql\Connection 
{
  public function __construct()
  {
    parent::__construct(
      'localhost',
      'test_db',
      'test_user',
      'supersecret'
    );
  }
}

$connection = new Connection();

$rows = $connection->fetch("SELECT * FROM `test_table`;");



use apsxj\mysql\Column;
use apsxj\mysql\Type;

class Table extends \apsxj\mysql\Table
{
  public function __construct()
  {
    parent::__construct(
      new Connection(),
      'test',
      array(
        new Column('id', Type::INT),
        new Column('created', Type::INT),
        new Column('updated', Type::INT),
        new Column('deleted', Type::BOOL),
        new Column('name')
      )
    );
  }

  public function insert($name)
  {
    $sql = "INSERT INTO `test` (`id`, `created`, `updated`, `deleted`, `name`) VALUES (NULL, ?, ?, 0, ?);";
    $date = date('U');
    $args = array($date, $date, $name);
    return $this->connection->insert($sql, $args);
  }
}

$table = new Table();

$table->insert('Test Name');