PHP-找不到oci_connect [英] PHP - oci_connect not found
问题描述
我研究发现oci_connect()是可行的方法.我发现我可以使用tnsnames.ora文件中的连接名称",也可以使用简单的连接语法.由于我的数据库不是本地存储的,而且我不知道tnsnames.ora文件在apex.oracle.com中的何处,因此我使用了简单的连接字符串.
I researched and found out oci_connect() is the way to go. I found out that i could either use the Connect Name from the tnsnames.ora file or use an easy connect syntax. Since my database isn't locally stored and I had no idea where the said, tnsnames.ora file was located in apex.oracle.com, I went with easy connect strings.Here's what I've done so far.
$username = "myemail";
$host = "apex.oracle.com";
$dbname = "name";
$password = "password";
// url = username@host/db_name
$dburl = $username . "@".$host."/".$dbname;
$conn = oci_connect ($username, $password, $dburl);
if(!$conn) echo "Connection failed";
我得到
Call to undefined function oci_connect()
那该怎么走?
这是我做过的事情:
-
已安装的Oracle数据库
Installed Oracle DB
解压缩的Oracle实例客户端
Unzipped Oracle Instance client
设置环境变量
在php.ini中取消注释extension = php_oci8_12c.dll
Uncommented the extension=php_oci8_12c.dll in php.ini
将所有* .dll文件从实例客户端文件夹复制到xampp/php和xampp/apache/bin
Copied all the *.dll files from the instance client folder to xampp/php and xampp/apache/bin
还确保php/ext文件夹具有所需的dll.
also made sure the php/ext folder had the required dlls.
那是昨晚.我已经多次重启PC,并用它进行了APACHE,但仍然出现此错误:
That was last night. I have restarted my PC multiple times, APACHE with it but I'm still getting this error:
Call to undefined function oci_connect()
在这一点上,我感到沮丧,不知道从这里去哪里. PHP似乎并没有链接到oci8.我可以通过"sqlplus"命令和一些select语句在cmd中查看从Database Configuration Assistant创建的数据库.因此,一切似乎都已正确安装,只是尝试使用oci_connect()
时遇到问题的php.
我的database.php,现在设置为:
At this point I'm frustrated and don't know where to go from here. PHP just doesn't seem to link up to oci8. I can view the databases I made from Database Configuration Assistant in cmd from 'sqlplus' command and a few select statements. So everything seems to be setup right, its just the php that's having problems trying to use oci_connect()
.
My database.php, now is setup as:
public function __construct()
{
error_reporting(E_ALL);
if (function_exists("oci_connect")) {
echo "oci_connect found\n";
} else {
echo "oci_connect not found\n";
exit;
}
$host = 'localhost';
$port = '1521';
// Oracle service name (instance)
$db_name = 'haatbazaar';
$db_username = "SYSTEM";
$db_password = "root";
$tns = "(DESCRIPTION =
(CONNECT_TIMEOUT=3)(RETRY_COUNT=0)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = $host)(PORT = $port))
)
(CONNECT_DATA =
(SERVICE_NAME = $db_name)
)
)";
$tns = "$host:$port/$db_name";
try {
$conn = oci_connect($db_username, $db_password, $tns);
if (!$conn) {
$e = oci_error();
throw new Exception($e['message']);
}
echo "Connection OK\n";
$stid = oci_parse($conn, 'SELECT * FROM ALL_TABLES');
if (!$stid) {
$e = oci_error($conn);
throw new Exception($e['message']);
}
// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
$e = oci_error($stid);
throw new Exception($e['message']);
}
// Fetch the results of the query
while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {
$row = array_change_key_case($row, CASE_LOWER);
print_r($row);
break;
}
// Close statement
oci_free_statement($stid);
// Disconnect
oci_close($conn);
}
catch (Exception $e) {
print_r($e);
}
}
它输出:
oci_connect not found
OCI8列在我的phpInfo().
推荐答案
好吧,我发现了整个苦难的罪魁祸首.我已经设置了PATH
环境变量,但是显然忘记了添加一个名为TNS_ADMIN
的新系统环境变量,并将目录设置为PATH/TO/INSTANCE/CLIENT
.
这是您需要添加的系统环境变量的列表:
Okay I found out the culprit behind this whole ordeal. I had set the PATH
Environment Variables but apparently forgot to add a new system environment variable named TNS_ADMIN
and set the directory to PATH/TO/INSTANCE/CLIENT
.
Here's the list of System Environment variable you need to add:
- 编辑
PATH
系统变量并添加$ORACLE_HOME/bin
目录 - 编辑
PATH
系统变量并添加实例客户端目录 - 添加新的系统变量,将其命名为
TNS_ADMIN
并添加实例客户端目录
- Edit
PATH
system variable and add the$ORACLE_HOME/bin
dir - Edit
PATH
system variable and add the Instance Client dir - Add new system variable, name it
TNS_ADMIN
and add the Instance Client dir
我希望这对那些来找人的人有帮助.
I hope this helps those who come looking.
这篇关于PHP-找不到oci_connect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!