---
title: "yii framework: sqlite with  \"could not find driver\" issue 解决方法"
author: "Heis"
date: "2013-09-12T16:03:44Z"
tags: []
categories: ["编程语言"]
slug: "yii-framework-sqlite-with-could-not-find-driver-issue"
draft: false
lastmod: "2013-09-12T16:04:40Z"
id: 1941445
url: "https://heis.iteye.com/blog/1941445"
---

根据yii framework的[官方教程](http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app),使用 sqlite，在利用Gii生成 Model skeleton 的过程中，很多人会遇到以下错误

 

```
CDbConnection failed to open the DB connection: could not find driver
```

 

 

我的是win7+apache+sqlite+PHPv5.3.27，这是我的解决方案：

 

1\. 检查PHP.ini是否启用了sqlite的扩展模块配置，要将这行前面的分号去掉。

 

```
extension=php_pdo_sqlite.dll
```

 

2\. 由于PHP5.2的默认查找扩展模块（Extension）路径是c:\\php，而这个版本的php\_pdo\_sqlite.dll文件是放在“PHP根路径/ext”文件夹下面，所以会导致加载失败。测试的时候可以在命令行输入

 

```
>PHP根路径\PHP.exe
```

 如果显示无法加载php\_pdo\_sqlite.dll，就是加载出了问题。

 

这时候可以通过修改PHP.ini文件去修改加载默认路径。找到extension\_dir这一项，修改为

 

```
extension_dir = 你的PHP根路径/ext
```

然后再次使用PHP.exe去测试，或者访问 [http://localhost/yii/requirements/index.php](http://localhost/yii/requirements/index.php) 查看“PDO SQLite扩展模块”这一项是否通过。