[英]How To Use Medoo Database In Codeigniter 4
I couldn't find the solution and the correct way to call a Medoo class to use in codeigniter 4. I could run it in codeigniter 3, but not codeigniter 4.我找不到调用 Medoo 类以在 codeigniter 4 中使用的解决方案和正确方法。我可以在 codeigniter 3 中运行它,但不能在 codeigniter 4 中运行它。
Below my error :
在我的错误之下:
And this is my code :这是我的代码:
File 1 (Dennis_layout_center) :
文件 1 (Dennis_layout_center):
namespace App\Controllers;
use App\Models\Dennis_medoo_model;
class Dennis_layout_center extends BaseController {
public function __construct()
{
}
// Show Command Layout
public function index()
{
$this->Command_Layout();
}
// Show Command Layout
public function Command_Layout() {
$Medoo = new Dennis_medoo_model();
$Data['Response'] = $Medoo->FFetchBotCommand();
echo view('index', $Data);
}
}
File 2 : (Dennis_medoo_model)
文件 2 : (Dennis_medoo_model)
namespace App\Models;
use CodeIgniter\Model;
class Dennis_medoo_model extends Model {
public $database;
public $maxfolder;
function __construct()
{
include APPPATH . 'ThirdParty/vendor/autoload.php';
include APPPATH. 'ThirdParty/medoo/vendor/catfan/medoo/src/Medoo.php';
$this->database = new Medoo([
// [required]
'type' => 'mysql',
'host' => 'localhost',
'database' => 'db_test',
'username' => 'test',
'password' => 'test',
// [optional]
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'port' => 3306,
// [optional] Table prefix, all table names will be prefixed as PREFIX_table.
'prefix' => '',
// [optional] Enable logging, it is disabled by default for better performance.
'logging' => true,
// [optional]
// Error mode
// Error handling strategies when error is occurred.
// PDO::ERRMODE_SILENT (default) | PDO::ERRMODE_WARNING | PDO::ERRMODE_EXCEPTION
// Read more from https://www.php.net/manual/en/pdo.error-handling.php.
'error' => PDO::ERRMODE_SILENT,
// [optional]
// The driver_option for connection.
// Read more from http://www.php.net/manual/en/pdo.setattribute.php.
'option' => [
PDO::ATTR_CASE => PDO::CASE_NATURAL
],
// [optional] Medoo will execute those commands after connected to the database.
'command' => [
'SET SQL_MODE=ANSI_QUOTES'
]
]);
}
}
I just call : $Medoo = new Dennis_medoo_model();我只是打电话: $Medoo = new Dennis_medoo_model();
But I got error in here : $this->database = new Medoo Which shown in Line 17.但是我在这里遇到错误: $this->database = new Medoo第 17 行所示。
When I call another model it is working.当我调用另一个模型时,它正在工作。
Edit : How is the correct way to use thirdparty in codeigniter 4编辑:如何在 codeigniter 4 中使用第三方的正确方法
What should I do now ?我现在该怎么办 ?
Thank You谢谢
I just missed this line :我只是错过了这一行:
// Using Medoo namespace. // 使用 Medoo 命名空间。
use Medoo\\Medoo;使用 Medoo\\Medoo;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.