我典型的PDO连接如下。如何在config.ini文件中设置特定于驱动程序的连接选项(即\PDO::ATTR_ERRMODE=>\PDO::ERRMODE_EXCEPTION
)而不将这些选项常量转换为它们的整数值?
<?php
$config=parse_ini_file(__DIR__.'/../config.ini', true, INI_SCANNER_TYPED);
$db = $config['mysql'];
$conn=new \PDO(
"mysql:host={$db['host']};port={$db['port']};dbname={$db['dbname']};charset={$db['charset']}",
$db['username'],
$db['password'],
[
\PDO::ATTR_EMULATE_PREPARES=>false,
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=>true,
\PDO::ATTR_ERRMODE=>\PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE=>\PDO::FETCH_ASSOC
]
);
config.ini
[mysql]
host = localhost
port = 3306
charset = utf8mb4
dbname = myDatabase
username = myUsername
password = myPassword
;options[PDO::ATTR_EMULATE_PREPARES] = false
;options[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true
;options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION
;options[PDO::ATTR_DEFAULT_FETCH_MODE] = PDO::FETCH_ASSOC
答案 0 :(得分:1)
根据马丁的评论,这就是我最终要做的事情:
<textarea id="content" class="main_editor" name="content"></textarea>
<input type="button" class="default-text" value="White" data-value="#ff0000" />
<script>
editor = CKEDITOR.replace("content");
$(document).on("click", ".default-text" , function(e) {
var color = $(this).data('value');
editor.document.$.childNodes[1].childNodes[1].style.color = color;
editor.focus();
});
</script>