1. Go to this page and download the library: Download orz/dbh 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/ */
namespace app\index\controller;
use think\Request;
use Dbh\thinkphp\provider\DbhProvider;
class Index extends Controller {
protected $dbi = null;
function _initialize(){
$this->dbi = DbhProvider::invoke($this->request);
parent::_initialize();
}
/**
* 测试1,属性注入后用助手函数request()调用
* http://test12.localhost.localdomain/index/index/test1
*/
function test1(){
$result = 'HelloThinkphp50';
$rw = request()->dbh();
$pdostmt = $rw->query('SELECT version() as version');
$version = $pdostmt->fetchAll();
var_dump($version); // [['version':'5.7.1']]
$log = $this->dbi->wlog('db');
$log->info($result);
return $result;
}
}
use Dbh\Laravel\Facades\DbhFacade as Dbf;
Dbf::wlog('db')->info('helloworld,1234');
$podstmt = Dbf::dbh()->query('SELECT version() AS version');
print_r($podstmt->fetchAll());
use Dbh\thinkphp\facade\DbhFacade as Dbf;
Dbf::wlog('db')->info('helloworld,1234');
$podstmt = Dbf::dbh()->query('SELECT version() AS version');
print_r($podstmt->fetchAll());
sql
SELECT * FROM _plog;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.