php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78423 ODBC functions work without extension=odbc
Submitted: 2019-08-16 23:59 UTC Modified: 2019-08-18 22:34 UTC
From: dpfender44 at gmail dot com Assigned:
Status: Not a bug Package: ODBC related
PHP Version: 7.4.0beta2 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dpfender44 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-08-16 23:59 UTC] dpfender44 at gmail dot com
Description:
------------
In both PHP versions 7.3.9RC1 and 7.4.0beta2, the php.ini file does not have the ODBC (extension=odbc) configured, but the ODBC functions work properly.

If the ODBC module is now part of the core PHP system, then the extension=odbc option in the php.ini file needs to be removed.

In PHP version 7.3.8, the extension=odbc option must be specified in php.ini.

I have done testing of ODBC functions on all three versions of PHP on the same computer system.  I just reconfigure the Fast CGI module of the IIS web server to switch between PHP versions.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-17 07:02 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2019-08-17 07:02 UTC] cmb@php.net
The ODBC extension is still supposed to be compiled as DLL (and as
such has to be explicitly loaded).  This is the case with
php-7.4.0beta2-nts-Win32-vs16-x64.  Which exact version did you
try?  Have you double-checked, that the desired php.ini is used?
 [2019-08-17 15:34 UTC] dpfender44 at gmail dot com
-Status: Feedback +Status: Assigned
 [2019-08-17 15:34 UTC] dpfender44 at gmail dot com
Two versions have the same symptom.
php-7.3.9RC1-nts-Win32-VC15-x64.zip
php-7.4.0beta2-nts-Win32-vs16-x64.zip
I have double checked the php.ini being used and php.ini has ";extension=odbc".
 [2019-08-17 15:38 UTC] requinix@php.net
-Status: Assigned +Status: Feedback
 [2019-08-17 15:38 UTC] requinix@php.net
To make sure,
1. There is no other extension=odbc line in there,
2. There are no other INI files being loaded, and
3. If you modify that same php.ini and reload IIS/FPM, you see the changes reflected in code?
 [2019-08-17 15:59 UTC] dpfender44 at gmail dot com
-Status: Feedback +Status: Assigned
 [2019-08-17 15:59 UTC] dpfender44 at gmail dot com
There is only one php.ini file and Fast CGI is use in IIS to process PHP files.
When I initially saw the problem, I tried changing the php.ini file to enable and then disable the extension=odbc line and saw no difference.
I even powered off the computer and then back on with the extension disabled and it still works.
I also searched the php.ini file for all occurrences of the string 'odbc' looking for another string that might enable it, but found none.
Testing on the same system with PHP 7.3.8 and the same PHP script, it detects when the function 'odbc_connect' is not available when changing the php.ini option.  PHP 7.3.9RC1 and 7.4.0beta2 have the same symptom.  I did not submit this bug report until I tested all 3 versions of PHP using the same PHP script.
 [2019-08-17 16:42 UTC] cmb@php.net
D:\Users\cmb>curl -L -s --output php-7.3.9RC1-nts-Win32-VC15-x64.zip https://windows.php.net/downloads/qa/php-7.3.9RC1-nts-Win32-VC15-x64.zip

D:\Users\cmb>7z x -ophp-7.3.9RC1-nts-Win32-VC15-x64 php-7.3.9RC1-nts-Win32-VC15-x64.zip > nul

D:\Users\cmb>cd php-7.3.9RC1-nts-Win32-VC15-x64

D:\Users\cmb\php-7.3.9RC1-nts-Win32-VC15-x64>php --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

D:\Users\cmb\php-7.3.9RC1-nts-Win32-VC15-x64>php -m | findstr odbc

D:\Users\cmb\php-7.3.9RC1-nts-Win32-VC15-x64>php -r "odbc_connect();"

Fatal error: Uncaught Error: Call to undefined function odbc_connect() in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1
 [2019-08-17 17:19 UTC] dpfender44 at gmail dot com
C:\WINDOWS\system32>cd \php740

C:\PHP740>php --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File:         C:\PHP740\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

C:\PHP740>php -m |findstr odbc

C:\PHP740>php -r "odbc_connect();"

Fatal error: Uncaught Error: Call to undefined function odbc_connect() in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1

C:\PHP740>
C:\PHP740>cd \php739

C:\PHP739>php --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File:         C:\PHP739\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

C:\PHP739>php -m |findstr odbc

C:\PHP739>php -r "odbc_connect();"

Fatal error: Uncaught Error: Call to undefined function odbc_connect() in Command line code:1
Stack trace:
#0 {main}
  thrown in Command line code on line 1

C:\PHP739>
C:\PHP739>cd \php738

C:\PHP738>php --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File:         C:\PHP738\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

C:\PHP738>php -m |findstr odbc
odbc

C:\PHP738>php -r "odbc_connect();"

Warning: odbc_connect() expects at least 3 parameters, 0 given in Command line code on line 1

C:\PHP738>
--PHP script--
<?php
if (!function_exists('odbc_connect'))
{
	echo "<br><br><b>Function odbc_connect does not exist!</b><br>\n";
	echo "Make sure that php.ini enables extension for odbc.<br>\n";
}
else
{
--------
This error never occurs in 7.3.9RC1 or 7.4.0beta2, only in 7.3.8. Mysterious.  The odbc functions work properly (odbc_connect, odbc_prepare, odbc_execute, odbc_num_rows) without php.ini enabled for odbc.  It fails if I disable odbc in 7.3.8.
 [2019-08-17 17:36 UTC] dpfender44 at gmail dot com
For PHP 7.4.0beta2, I removed the php.ini file and the odbc functions still work, but another script using mysqli_connect fails.
C:\PHP740>php --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

C:\PHP740>
 [2019-08-17 17:41 UTC] dpfender44 at gmail dot com
It seems that the php-cgi.exe has odbc included, but php.exe does not.
 [2019-08-17 17:46 UTC] phpbugreports at gmail dot com
what about compare the output of "php.exe -n -m" and "php-cgi.exe -n -m" so that you can easily bypass "seems" and "assumptions"
 [2019-08-17 17:59 UTC] requinix@php.net
-Status: Assigned +Status: Feedback
 [2019-08-17 19:06 UTC] dpfender44 at gmail dot com
-Status: Feedback +Status: Assigned
 [2019-08-17 19:06 UTC] dpfender44 at gmail dot com
C:\PHP740>php --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

C:\PHP740>php.exe -n -m
[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
filter
hash
iconv
json
libxml
mysqlnd
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

C:\PHP740>php-cgi.exe -n -m
[PHP Modules]
bcmath
calendar
cgi-fcgi
Core
ctype
date
dom
filter
hash
iconv
json
libxml
mysqlnd
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]


C:\PHP740>
 [2019-08-17 19:15 UTC] dpfender44 at gmail dot com
This is the PHP script that works without php.ini file.
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>ODBC Test 5</title>
 </head>
 <body>
<?php
if (!function_exists('odbc_connect'))
{
	echo "<br><br><b>Function odbc_connect does not exist!</b><br>";
	echo "Make sure that php.ini enables extension for odbc.<br>";
}
else
{
	$exprect_res_cnt = 2;
	$db_name = "test_db";
	$db_table = 'test_info';
	echo "<br><br>db name ({$db_name}), db table ({$db_table}), expect <b>res_cnt ({$exprect_res_cnt})</b><br>";
	$server = 'djpnet5.dyndns.org';
	$dsn = "Driver={MySQL ODBC 8.0 Unicode Driver};Server=$server;Database=$db_name;";
	echo "<br><br>ODBC Connector string (<b>{$dsn})</b><br>";
	$user = 'root3';
	$password = "djp777!123";
	$cid = @odbc_connect($dsn, $user, $password);
	if ($cid)
	{
		$qstr = "SELECT * FROM {$db_table}";
		$res_id = odbc_prepare($cid, $qstr);
		if ($res_id)
		{
			$res = odbc_execute($res_id);
			if ($res)
			{
				$res_cnt = odbc_num_rows($res_id);
				echo "<br><br>got <b>res_cnt ({$res_cnt})</b><br>";
			}
			else
			{
				echo "<br><br><b>Failed to execute!</b><br>";
			}
		}
		else
		{
			echo "<br><br><b>Failed to prepare!</b><br>";
		}
	}
	else
	{
		echo "<br><br><b>Failed to connect!</b><br>";
		echo "Connection string ({$dsn})<br>";
	}
}
?>
 </body>
</html>
 [2019-08-18 10:20 UTC] cmb@php.net
-Status: Assigned +Status: Open -Assigned To: cmb +Assigned To:
 [2019-08-18 10:20 UTC] cmb@php.net
With the additional information, this looks like ODBC is not
compiled statically.  You can verify that with ProcessExplorer[1]
which probably shows that php_odbc.dll is loaded.

Anyhow, I actually tested with IIS now, and the ODBC extension is
only available if I add `extension=odbc` to php.ini (and restart
IIS).  So this looks like a configuration issue on your machine.

[1] <https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer>
 [2019-08-18 18:27 UTC] dpfender44 at gmail dot com
I have solved the problem. I have 3 versions of PHP installed on my system in 3 folders: C:/PHP738, C:/PHP739, C:/PHP740. I removed all php.ini files and then my script fails because odbc is not loaded.  I then added back the php.ini into C:/PHP738 (which has odbc enabled) and then the PHP 7.4.0 web server loads the php.ini info from folder C:/PHP738 and the script works. It must be something in Windows or IIS that is finding a copy of php.ini in a cache and using it instead of what is in the folder for the version of PHP being used by IIS.
Sorry for all the grief that I have caused, but this was a really strange situation.
 [2019-08-18 19:05 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: PHP options/info functions +Package: ODBC related
 [2019-08-18 19:05 UTC] requinix@php.net
Good to hear you got that sorted out.
 [2019-08-18 20:38 UTC] cmb@php.net
I suggest to check the php.ini search location docs[1].  If your
case isn't documented there, please report a respective doc bug.
Thanks.

[1] <https://www.php.net/manual/en/configuration.file.php>
 [2019-08-18 21:18 UTC] dpfender44 at gmail dot com
The only place php.ini files exist are in the directories that contain PHP programs (php.exe).  There are no registry keys or environment variables related to php.ini files.  I do not know what kind of search php.exe or php-cgi.exe does to find php.ini files. It must be Windows or IIS that keeps a copy in cache and uses it when one is not found in the folder where php-cgi.exe exists.  The only thing that I can do with multiple versions of PHP on the same system is to make sure that a php.ini file only exists in the one currently configured in IIS for Fast CGI processing.
 [2019-08-18 22:34 UTC] dpfender44 at gmail dot com
I just found something in the IIS configuration regarding FastCGI Settings that was the cause of my problems. I never had any problems with multiple PHP versions on one system because the php.ini file always had the same options specified until I started testing ODBC processing.  All is now resolved and there is no problem with any of the PHP software.  This affected all of the PHP versions installed on my system.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 17:01:27 2019 UTC