一:要确定PHP 当前的版本信息 phpInfo(); 就能查出对应的信息
PHP 版本 7.4 64位 Thread Safety : disabled
根绝不同的PHP版本选择下载Oci8, 选择Dll 下载
二:选择好oic8的版本后进入该页面。64位就选择 x64 , 32位 就选择x86
(1)Thread Safety : disabled (就要选择【Non Thread Safe (NTS) x64】)
(2)Thread Safety : enabled? (就要选择【Non Thread Safe (NTS) x64】)
三:把下载内容丢到对应的PHP版本的ext 文件夹
四:查询需要链接Orcle 的版本号,获取版本号,例如:11.2
五:还需要下载?instantclient-basic-nt? 下载地址:Oracle Instant Client Downloads。根据window不同的版本去下载,例如我们需要下载的是11.2,?instantclient-basic-win-x86-64-11.1.0.7.0.zip
六:下载后解压并且把路径指向对应的位置:记住是高级环境变量中的"系统的"PTAH
七:重启PHP,在phpinfo() 就能看到加载oci8
八:最后尝试数据库链接
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$username = "hr"; // Use your username
$password = "welcome"; // and your password
$database = "localhost/orclpdb"; // and the connect string to connect to your database
$query = "select * from dual";
$c = oci_connect($username, $password, $database);
if (!$c) {
$m = oci_error();
trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
}
$s = oci_parse($c, $query);
if (!$s) {
$m = oci_error($c);
trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);
}
$r = oci_execute($s);
if (!$r) {
$m = oci_error($s);
trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);
}
echo "<table border='1'>\n";
$ncols = oci_num_fields($s);
echo "<tr>\n";
for ($i = 1; $i <= $ncols; ++$i) {
$colname = oci_field_name($s, $i);
echo " <th><b>".htmlspecialchars($colname,ENT_QUOTES|ENT_SUBSTITUTE)."</b></th>\n";
}
echo "</tr>\n";
while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo "<tr>\n";
foreach ($row as $item) {
echo "<td>";
echo $item!==null?htmlspecialchars($item, ENT_QUOTES|ENT_SUBSTITUTE):" ";
echo "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
?参考文章:https://blogs.oracle.com/opal/post/installing-xampp-on-windows-for-php-and-oracle-database
|