任何提示连接我的php到我的oracle数据库?(FreeBSD 12.1 AMD)



我正在使用FreeBSD 12.1与amd, php73,我试图连接我的oracle数据库。我做了一些尝试,但无济于事,显然是一个丢失的驱动器丢失了FreeBSD + AMD。

FreeBSD server.privatusdev.com.br 12.1-STABLE FreeBSD 12.1-STABLE #1 r361584M: Wed Sep 2 18:15:32 -03 2020 root@iso.proapps.serveru.us:/usr/obj/usr/src/amd64.amd64/sys/PROAPPS amd64

PHP 7.3.18 (cli) (built: Jun 15 2020 18:55:03) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.18, Copyright (c) 1998-2018 Zend Technologies

嗯,我的第一个尝试是连接PDO:

$db_username = "USERX";
$db_password = "PASSWORD";
$db = "oci:dbname=MYIP:MYPORT/orcl";
$conn = new PDO($db, $db_username, $db_password);
$stmt = $conn->exec("Select * from MYTABLE"); 

和我有这个错误:

[Fail to executed api. Return: "could not find driver" Code: 0, FileLine/Oracle.php:35 exception_type: PDOException]

我的第二次尝试是通过odbc_connect连接

$user = "USERX";
$password = "PASSWORDY";
$ODBCConnection = odbc_connect("Driver={Devart ODBC driver for Oracle};Direct=true;Host=MYIP;Port=MYPORT;Service Name=orcl;User ID=USERX;password=PASSWORDY", $user, $password);

还有,你猜怎么着:

[Fail to executed api. Return: "odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib 'Devart ODBC driver for Oracle' : file not found, SQL state 01000 in SQLConnect" Code: 2, FileLineOracle.php:28 exception_type: yiibaseErrorException]

嗯,在理解驱动器丢失后,我开始尝试安装PDO或负责oracle db的PECL。

我做的第一件事是在freebsd包中寻找oracle

(root@server) /home/tiago# pkg search php | egrep -i "oracle|oci|oci8|orcl" --colorExit 1

好的,如果你没有在pkg中有它,它可能存在于ports中。让我们看看那里?

# cd /usr/ports/databases/oracle8-client/ && make install clean
===>  oracle8-client-0.2.0_2 is only for i386, while you are running amd64.
*** Error code 1
Stop.
make: stopped in /usr/ports/databases/oracle8-client
Exit 1

没有失去希望,我试着想得更简单,通过PECL安装,但在下载之前,我在互联网上看到了一个建议,下载SDK并将其放在特定的文件夹中,并将其放在特定的文件夹中,并在安装时将路径传递到该SDK文件夹..

#pecl install oci8-2.2.0
Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect]: instantclient,/opt /oracle/instantclient_12_2

但是,我现在有这个错误:

checking Oracle Instant Client library version compatibility... configure: error: Oracle Instant Client libraries libnnz.so and libclntsh.so not found
ERROR: `/tmp/pear/oci8/configure --with-php-config=/usr/local/bin/php-config --with-oci8=instantclient,/opt/oracle/instantclient_19_8/' failed

我试图安装这些丢失的libd,但是我找不到任何可以安装它的包。

:在那一刻,我失去了希望,我来向社区寻求帮助

经过近3周的斗争,我找到了一个解决问题的方法。在做任何事情之前,让我们先考虑一下。没有适合FreeBSD的Oracle ODBC,所以解决这个问题的最好方法是找到一个使用本地库连接到我的Oracle的系统,而不必在我的操作系统上安装连接器。由于上帝的奇迹,我记得有。netcore,它通过DLL与oracle对话,也就是说,不管你使用哪个操作系统,DLL都会一直运行,你只需要在你的操作系统上运行。netcore。为此,遵循我所遵循的步骤:

按照以下步骤下载并安装.netcore到你的freebsd x64(在这个选项中,我留下了3.0.0版本,他的解释更完整,但我选择使用3.1.1版本的SDK) jasonpugsley/installer

安装完成后,我在visual studio中创建了一个小项目,以便快速连接到数据库。

using System;
using Oracle.ManagedDataAccess.Client;
namespace oracle
{
class Program
{
static void Main(string[] args)
{
using (OracleConnection connection = new OracleConnection("User Id=hr;Password=oracle;Data Source=//localhost:1521/orcl"))
{
using (OracleCommand cmd = connection.CreateCommand())
{
try
{
connection.Open();
cmd.BindByName = true;
cmd.CommandText = "select * from countries";
OracleDataReader reader = cmd.ExecuteReader();
Console.WriteLine("rows" + reader.HasRows);
while (reader.Read())
{
Console.WriteLine(reader.GetValue(0));
Console.WriteLine(reader.GetString(0));
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
connection.Close();
}
Console.WriteLine("okay, its works guys! its alive. thx odin");
}

}

}

啊,我只需要通过nuget下载Oracle for .netcore

那么,我实现的想法是什么,并且100%有效:

我的PHP,当你需要与oracle对话时,PHP打开一个连接到。netcore并与oracle进行对话。朋友们,希望我能帮到你们!

PS:特别感谢jasonpugsley用freebsd发布了这个。netcore文档,它帮助了我很多!jasonpugsley

最新更新