PHP code example of cwola / a5m2-invoker

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

    

cwola / a5m2-invoker example snippets




use Cwola\A5M2\Invoker\Configs;
use Cwola\A5M2\Invoker\Executor;

/* 設定 */
$configs = new Configs(設定ファイルのパスを指定します(任意));

// 後から設定ファイルを読み込むことも可能です。
// 設定ファイルに存在しないプロパティは上書きされないので、設定ファイルの継承を疑似的に行うことが可能です。
$configs->load(__DIR__ . DIRECTORY_SEPARATOR . 'extends.json');

// 直接プロパティへ値をセットすることも可能です。
$configs->provider = Configs::PROVIDER_POSTGRES;
$configs->connectionType = Configs::CONNECTION_INTERNAL;


/* execute */
$executor = new Executor($configs);
$executor->defaultFetchMode = Executor::FETCH_ASSOC;
$executor->listType = 'Illuminate\\Support\\Collection';

if (!$executor->execute('SELECT * FROM foo WHERE status = :status;', ['status' => true])) {
    // outputsプロパティはdebugプロパティがtrueの場合にのみ設定されます
    throw new Exception(join("\n", $executor->outputs));
}

$result = $executor->fetch();
echo 'QUERY : ' . $executor->executedQuery . PHP_EOL;
echo 'TIME : ' . $executor->execTime . '[ms]' . PHP_EOL;
echo 'COUNT : ' . $executor->columnCount . PHP_EOL;
echo 'RESULT : ' . PHP_EOL;
var_dump($result);  // Illuminate\Support\Collection<array>

$result = $executor->fetch(Executor::FETCH_CLASS, 'stdClass');
echo 'RESULT : ' . PHP_EOL;
var_dump($result);  // stdClass[]