Exemple #1
0
Fichier : sql.php Projet : urn2/nx
<?php

require '../../autoload.php';
\nx\autoload::register();
trait test_db
{
    public function insert($sql, $params = [], $config = 'default')
    {
        echo '<br><br>[', $config, ']', $sql, '<br>', json_encode($params);
    }
    public function select($sql, $params = [], $config = 'default')
    {
        echo '<br><br>[', $config, ']', $sql, '<br>', json_encode($params);
    }
    public function execute($sql, $params = [], $config = 'default')
    {
        echo '<br><br>[', $config, ']', $sql, '<br>', json_encode($params);
    }
}
class app extends \nx\app
{
    use test_db, \nx\db\table;
    var $setup = ['db.pdo' => ['default' => ['dsn' => 'mysql:dbname=cdcol;host=127.0.0.1;charset=UTF8', 'username' => 'root', 'password' => '', 'options' => []]]];
}
echo '<br><br>init:', <<<'EOT'
$app =new app();
$sql =$app->table('cds', 'id');
EOT;
$app = new app();
$sql = $app->table('cds', 'id');
$sql->create([['titel' => 1, 'interpret' => 2], ['titel' => 2, 'interpret' => 2], ['titel' => 3, 'interpret' => 2]]);
Exemple #2
0
<?php

include "../src/autoload.php";
\nx\autoload::register([]);
$queue = new \nx\queue();
$queue->append(function ($result, $a, $b, $c) {
    echo 'before 1', PHP_EOL;
    $result['num'] = 1;
    yield;
    $result['num'] = 10;
    echo 'after 1', PHP_EOL;
});
$queue->append(function ($result, $a, $b, $c) {
    echo 'before 2', PHP_EOL;
    $result['num'] = 2;
    yield;
    $result['num'] = 20;
    echo 'after 2', PHP_EOL;
});
$result = $queue->middleware(1, 2, 3);
var_dump($result);
$queue->append(function ($result, $a, $b, $c) {
    return $a . ' 1';
});
$queue->append(function ($result, $a, $b, $c) {
    return $result . ' 2';
});
$queue->append(function ($result, $a, $b, $c) {
    return $result . ' 3';
});
$result = $queue->pipe(0, 1, 2, 3);
<?php

namespace demo;

define('AGREE_LICENSE', true);
//框架常量
error_reporting(E_ALL);
//错误报告
date_default_timezone_set('Asia/Shanghai');
//设定默认时区
require '../src/autoload.php';
//框架自动加载路径,可使用composer替换
\nx\autoload::register(['demo' => ['.']]);
//自动加载注册,可在其中指定命名空间第一段指向目录
// \demp\app
class app extends \nx\app
{
    use \nx\router\ca, \nx\control\mvc, \nx\log\header, \nx\response\web, \nx\response\view;
}
app::factory([])->run();