如果机器安装了oracle(oci8和/或pdo_oci),如何使用php检测?

如果机器具有oracle (oci8和/或pdo_oci),我如何使用php检测? / code>已安装?</ p>

我正在开发一个 PHP </ code>项目,其中一些开发人员(例如我自己)安装了它,但是对于这些开发人员来说几乎没有必要 拥有它。 如何编写一个快速函数在代码中使用,以便我的主题能够处理网站的外观,而不会让它们崩溃?</ p>
</ div>

展开原文

原文

How can I detect, using php, if the machine has oracle (oci8 and/or pdo_oci) installed?

I'm working on a PHP project where some developers, such as myself, have it installed, but there's little need for the themers to have it. How can I write a quick function to use in the code so that my themers are able to work on the look of the site without having it crash on them?

4个回答



如果未安装oci扩展名,那么farside.myopenid.com的答案就会出现致命错误,你可以使用 function_exists('oci_connect')或extension_loaded('oci8')(或实际调用的扩展名)</ p>
</ div>

展开原文

原文

if the oci extension isn't installed, then you'll get a fatal error with farside.myopenid.com's answer, you can use function_exists('oci_connect') or extension_loaded('oci8') (or whatever the extension's actually called)

The folks here have pieces of the solution, but let's roll it all into one solution.

For just a single instance of an oracle function, testing with function_exists() is good enough; but if the code is sprinkled throughout to OCI calls, it's going to be a huge pain in the ass to wrap every one in a function_exists() test.

Therefore, I think the simplest solution would be to create a file called nodatabase.php that might look something like this:

<?php
// nodatabase.php
// explicitly override database functions with empty stubs. Only include this file
// when you want to run the code without an actual database backend. Any database-
// related functions used in the codebase must be included below.
function oci_connect($user, $password, $db = '', $charset='UTF-8', $session_mode=null)
{
}

function oci_execute($statement, $mode=0)
{
}
// and so on...

Then, conditionally include this file if a global (say, THEME_TESTING) is defined just ahead of where the database code is called. Such an include might look like this:

// define("THEME_TESTING", true) // uncomment this line to disable database usage
if( defined(THEME_TESTING) )
  include('nodatabase.php'); // override oracle API with stub functions for the artists.

Now, when you hand the project over to the artists, they simply need to make that one modification and they're good to go.

dongquanjie9328
dongquanjie9328 关键是你必须能够在实际调用实际函数之前加载存根函数。 如果是这样,您应该能够使概念工作:记录使用哪个OCI / PDO调用,编写存根函数库/骨架类,并根据需要有条件地包含该类。
大约 12 年之前 回复
duanjingwei7239
duanjingwei7239 如果我控制所有代码,这将是理想的。 不幸的是,所有直接oracle接口代码都由我们的客户端维护和更新,并且使用oci8和pdo_oci。 所以,我不确定这个解决方案是否有效 - 不是说我不会在星期一试一试。
大约 12 年之前 回复

I dont know if I fully understand your question but a simple way would be to do this:

<?php
  $connection = oci_connect('username', 'password', 'table');
  if (!$connection) {
    // no OCI connection.
  }
?>

As mentioned above by Greg, programmatically you can use the function_exists() method. Don't forget you can also use the following to see all the environment specifics with your PHP install using the following:

<?php
phpinfo();
?>
dpz7935
dpz7935 是的......但这只是打印到屏幕上的细节。 我想知道具体是什么,而不是在屏幕上打印。
大约 12 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐