我正在尝试将CodeIgniter 3项目连接到运行WAMP的Web服务器上的SQL Server 2008。
我尝试使用sqlsrv,odbc和pdo dbdrivers连接到数据库,但仍然无法执行。
这是我到目前为止尝试过的,
sqlsrv
和pdo_sqlsrv
出现在WAMP本地主机页面和phpinfo()页面上这是我的database.php文件,
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '172.20.15.52',
'username' => 'ivrserver',
'password' => 'ivrserver',
'database' => 'HMS-Migration',
'dbdriver' => 'sqlsrv',
'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
);
但是我在项目的每个页面上都遇到此错误,
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:/wamp64/www/ghms/system/database/DB_driver.php
Line Number: 436
我尝试使用ODBC连接器。我从ODBC数据源创建了系统DNS,该数据源连接到SQL Server数据库并以以下方式更改database.php,
$db['default'] = array(
'dsn' => '',
'hostname' => 'mssqltest',
'username' => 'ivrserver',
'password' => 'ivrserver',
'database' => 'HMS-Migration',
'dbdriver' => 'odbc',
'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
);
这能够连接数据库,但结果为Query Builder doesn't work with ODBC。 ¯\ _(ツ)_ /¯
然后我尝试使用pdo连接到SQL Server,并对database.php进行了以下更改
$db['default'] = array(
'dsn' => 'sqlsrv:server=172.20.15.52,1433;Database=HMS-Migration',
'hostname' => '',
'username' => 'ivrserver',
'password' => 'ivrserver',
'database' => '',
'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
);
这要求我为PHP安装sql驱动程序,但我想我已经安装了它们!
A Database Error Occurred
SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712
Filename: C:/wamp64/www/ghms/system/database/drivers/pdo/pdo_driver.php
Line Number: 142
我回去检查驱动程序的安装,
php_pdo_sqlsrv_7_ts_x64.dll
php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x64.dll
尽管我已经尽力检查了所有事情,因为它仍然没有连接到数据库-我在某个地方一定是错的。将CodeIgniter 3项目连接到SQL Server的正确方法是什么?
我想我找到了解决方案。 pdo dbdriver上的错误要求我安装用于MS SQL的ODBC驱动程序,但我却检查了用于MS SQL的PHP驱动程序。我去了错误中的链接,下载了ODBC驱动程序,现在看来可以正常工作!愚蠢的我!
答案 0 :(得分:0)
尝试此操作。定义您的sqlsrv:
AlertDialog.Builder builder = new AlertDialog.Builder(context);//Context is activity context
final EditText input = new EditText(context);
builder.setTitle(getString(R.string.remove_item_dialog_title));
builder.setMessage(getString(R.string.dialog_message_remove_item));
builder.setTitle(getString(R.string.update_qty));
builder.setMessage("");
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
input.setHint(getString(R.string.enter_qty));
input.setTextColor(ContextCompat.getColor(context, R.color.textColor));
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setText("String in edit text you want");
builder.setView(input);
builder.setPositiveButton(getString(android.R.string.ok),
(dialog, which) -> {
//Positive button click event
});
builder.setNegativeButton(getString(android.R.string.cancel),
(dialog, which) -> {
//Negative button click event
});
AlertDialog dialog = builder.create();
dialog.show();