最近学习thinphp5,连接Oracle数据库的时候遇到"could not find driver"的问题,实际上出现这个提示的原因可能有很多种,解决方法如下:
1)要打开php.ini中的相关扩展项,即将
extension=php_oci8.dll和extension=php_pdo_oci.dll前面的分号去掉
2)一定要装Oracle的客户端
3)将Oracle客户端目录下的oci.dll复制到php的ext目录中.
4)重启服务
测试脚本如下
<?php
/**
* Created by mestars.
* User: mestars
* Date: 6/13/16
* Time: 10:52 PM
*/
header('Access-Control-Allow-Origin: *');
$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.11)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = your_dbname)
)
)
";
try {
$conn = new PDO("oci:dbname=".$tns, 'username', 'password');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo '<br>';
foreach(PDO::getAvailableDrivers() as $driver)
echo $driver, '<br>';
还不快抢沙发