gpt4 book ai didi

php - 如何在 codeigniter 3 中使用 PDO

转载 作者:行者123 更新时间:2023-11-30 22:36:29 25 4
gpt4 key购买 nike

Codeignitier 显示我刚刚从 echo“加载”,但是当我尝试使用 PDO 执行此操作时表是空的:

function loadCSVtoDB($csvfile){
$stmt = $this->db->conn_id->prepare("LOAD DATA LOCAL INFILE :file
INTO TABLE `historic` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'");
$stmt->bindParam(":file",$csvfile);
$stmt->execute();
echo 'loaded';
//echo $this->db->conn_id->error_message();
}

我的数据库配置是:

$db['default'] = array(
'dsn' => '',
'hostname' => 'mysql:host=localhost',
'username' => 'zzazfhvsnt',
'password' => 'censored',
'database' => 'zzazfhvsnt',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

当我删除 conn_id 时,我得到

Fatal error: Call to undefined method CI_DB_pdo_mysql_driver::prepare()

当我更改 exec 而不是 prepare 时也是如此。

我在构造函数中这样调用它:

$this->load->model('Historic_model');
$this->Historic_model->loadCSVtoDB("assets/csv/1516E0.csv");

在自动加载中是:$autoload['libraries'] = array('database');

最佳答案

尝试使用下面的代码 'dsn' => 'mysql:host=localhost;数据库名=我的项目; charset=utf8;',

然后自动加载数据库library

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn' => 'mysql:host=localhost; dbname=myproject; charset=utf8;',
'hostname' => 'localhost',
'username' => 'root',
'password' => '*********',
'database' => '',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '' ,
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

关于php - 如何在 codeigniter 3 中使用 PDO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com