PHP 7.0 ODBC-Driver for Windows - php

I upgraded my PHP 5.6.30 (https://www.apachefriends.org/de/download.html) to PHP 7.0 (https://bitnami.com/stack/wamp/installer)
Everything worked fine so far and it reduces the loading time from my Page from 1,2 seconds to ~300 ms, when I use a MySQL-Database. But now I'm trying to connect to a MSSQL-Database with the following simple script, that worked fine with my old installation (PHP 5.6):
<?php
//Use the machine name and instance if multiple instances are used
$server = 'Server-Adress';
$user = '';
$pass = '';
//Define Port
$port='Port=1433';
$database = 'Databasename';
$connection_string = "DRIVER={SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
if ($conn) {
echo "Connection established.";
} else{
die("Connection could not be established.");
}
$sql = "SELECT * FROM st3_200 WHERE identifier = 1";
$result = odbc_exec($conn,$sql);
// Get Data From Result
while ($data[] = odbc_fetch_array($result));
// Free Result
odbc_free_result($result);
// Close Connection
odbc_close($conn);
// Show data
print_r($data);
?>
But now I got an error in my logs that says:
[Thu Dec 10 11:55:26.629956 2015] [:error] [pid 260:tid 968] [client
::1:63003] PHP Fatal error: Uncaught Error: Call to undefined
function odbc_connect() in
C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs\test\query.php:11\nStack
trace:\n#0 {main}\n thrown in
C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs\test\query.php on
line 11
First I thought, that my php.ini has a missing extension, so I enabled "extension=php_pdo_odbc.dll"
the difference from the php.ini in the 5.6 version is there is the extension:
"extension=php_mssql.dll" enabled. But I can't find them in the new PHP 7.0.ini
So my intension is there is no existing driver for odbc and PHP 7 yet?
I found some driver for Linux here:
https://aur.archlinux.org/packages/php7-odbc/
But I need something for my Windows environment.
Does anyone had the same issue and has already fixed it?
Thank und Greeting
Domi

Take a look in your php.ini, the string
extension=php_odbc.dll
seems to be missing in new installations, at least i had to add it manually in my new XAMPP installation (7.0.1)
and accidently just activated the pdo_odbc.dll

PHP7 has a few modules disabled by default that were previously enabled in PHP5.
It's an easy fix though since the extension should already exist in the \ext\ folder that came with PHP7. You just need to modify your php.ini file to include the line:
extension=php_odbc.dll
The line above is not already present and commented out; you actually need to add it!
PHP looks for the php.ini file in C:\Windows\ but it may also be located elsewhere on your machine. So check both C:\Windows\ and C:\php\ or where ever else you may have installed PHP.
After making the change you can check the results from the command line like this:
C:\php\php.exe -m
or (after restarting the web server / machine) from a .phtml file like this:
<? phpinfo(); ?>
That will output a list of enabled modules which should now include odbc; if not, then you may have modified the wrong php.ini file (keep looking) or forgot to restart the web server / machine.
Tips:
If you have a non-standard installation, you can use an absolute path like this:
extension=C:\php7x64\ext\php_odbc.dll

extension=php_mssql.dll (or extension=php_sqlsrv_56_nts.dll if you get it from Microsoft Drivers for PHP), is your problem: the Microsoft SQL driver for PHP 7 is not yet ready, the latest ETA is late January for the beta.
It looks like the cause of the delay is the intention to include SQL 2016 in that driver so you can migrate easier in the future.
UPDATE (2016/02/12):
As stated here (meet-bhagdev reply), there is an "early technical preview" of the PHP sqlsrv driver for Windows available on github.

Open your php.ini file and uncomment or add the following lines:
extension_dir = "C:\PHP\ext" ;<- your PHP path
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Reset Internet Information Services:
On command prompt with admin rights type:
iisreset
This fixed the problem for me.

As an addition to Adrian B`s which mentions the official driver, you can also check https://github.com/thomsonreuters/msphpsql
This is an unofficial port. However there are limitations for the time being.
Supports only sqlsrv ODBC but not PDO
Doesn`t support ZTS, only NTS
Supports only x86
It supports a subset of ODBC functions , you can see the list on the page.

We need x86 driver from Microsoft.
http://www.microsoft.com/ja-jp/download/details.aspx?id=13255
*Sorry, 'ja-jp' is mine. Please select your country. There are 2 drivers, one is 32bit, but we need 64bit(x86) version.
Then we could set "ODBC data source (64bit)". It appears on the window.
Last, check your web. Maybe it works.
Mar. 29th. 2016 Naio

I guess you was right, you need download the SQL Server ODBC driver for your PHP client platform and OS.
Here is the link for the similar issue: Call to undefined function odbc_connect()
also you can try to install this connector for MySQL (if you use MySQL): Connector/ODBC
or if you use MSSQL: ODBC Driver 11 for SQL Server

I know this question is rather old. But I've come across the same issue recently ...
#Naio is right : there are indeed different versions of ODBC drivers, based on the architecture (32bits or 64bits). The driver that PHP uses depends on its own version.
In other words, if you are using a 32bits ODBC environement, make sure to use a 32bits version of PHP ...
My guess is that, by switching from PHP 5.6 to PHP 7.0 you also switched from a 32bits version to a 64bits version.

Related

Installing on XAMPP PHP7.4.11 SQLSRV drivers [duplicate]

I trying to connect to an SQL Server in PHP. With XAMPP on my local machine, everything works well. But now I going to bring my application on the production server.
On this server there is installed the Microsoft IIS 6.1 and running the PHP version 7.0.7. I also installed the ODBC Driver from here. Next I decomment the following line in my php.ini file:
extension=php_sqlsrv_7_nts.dll
extension=php_pdo_sqlsrv_7_nts.dll
I got the files from the official microsoft site.
What's my problem?
Unfortunately, after I restarted the IIS. The PDO function throws the PDOException error with the following message:
could not find driver
For the connection I am using the following function which works pretty well on my local machine:
try {
$con = new PDO("sqlsrv:Server=" . SERVER . ";Database=" . DATABASE, USERNAME, PASSWORD);
// set the PDO error mode to exception
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "No connection: " . $e->getMessage();
exit;
}
What can I else do?
Here is detailed process if it's helpful for someone. PHP Version - 7.4
Download and extract the .dll files from this link - https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
Paste the files in C:\xampp\php\ext, your path could be different.
in php.ini add those two lines at bottom or in extension section.
extension=php_sqlsrv_74_ts_x64.dll
extension=php_pdo_sqlsrv_74_ts_x64.dll
Restart your Xampp server, I'll suggest restart your computer and everything will work without an issue then.
Check if SqlSRV enabled
Check using phpinfo() or http://localhost/dashboard/phpinfo.php at like this -
Hope, it will help someone.
After I found the error log on the Windows Server, I solved the error by myself.
I got this error in my log:
[21-Apr-2017 07:12:14 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '...\ext\php_pdo_sqlsrv_7_nts.dll' - %1 is not a valid Win32 application. in Unknown on line 0
Then I downloaded again the driver and installed the x64-Driver. Finally It works without any problems.
please notice you must use the correct version of php_sqlsrv_xx_xts_xxx.dll and php_pdo_sqlsrv_xx_xts_xx.dll files.
for exmple if you use php version 7.4 and a 64 bit system and wamp you must download and use these files:
php_sqlsrv_74_ts_x64.dll
php_pdo_sqlsrv_74_ts_x64.dll
for download you can use this site:
https://go.microsoft.com/fwlink/?linkid=2152937
https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
It took some time for me to solve the 'No driver'-error. I went through some steps as mentioned here and found some other ones that helped me after new errors. For future references:
Download the latest drivers from Microsoft (as said by Julian Schmuckli).
Check if your XAMPP is 64 bits(!) with Phpinfo(). If you've got 32-bit, you need different drivers.
Add the drivers to your Php.ini file and save the dll's in your php/ext-folder (question of saber tabatabaee yazdi).
For the connection, use this code:
$dbh = new PDO ("sqlsrv:Server=$server;Database=$dbname",$username,$pw);
If you add a port, use:
$server = "192.168.1.15, 51022";
Where the IP (can be hostname to) is your server and 51022 your port.

Error connecting to SQL Anywhere 16 with php 7.1.7 (dbcapi.dll not found)

I run a IIS Webserver with php 7.1.7 and the propriate SQL Anywhere extension.
Anywhere Client is installed in 32bit and 64bit version.
When connecting to database with
$conn = sasql_connect("UID=***;PWD=***;ENG=MyEng;LINKS=tcpip{host=192.168.2.204;port=2638}");
I receive as error:
The SQLAnywhere client libraries could not be loaded. Please ensure
that dbcapi.dll can be found in your PATH environment variable.
But all seems to be fine:
dbcapi.dll is in c:\Program Files\SQL Anywhere16\BIN32 and ...\BIN64
both paths are included in PATH variable and also shown in phpinfo
SQL Anywhere is shown in phpinfo output as well
What else can I check?
Regards
Florian
actually I don't know really why, as all settings, variables, taskes are same, but after a server reboot, now message is gone and it works.
Florian

Class 'Memcache' not found & PHP

I installed memcached by reading this article on Windows7 but unfortunately i keep getting error Fatal error: Class 'Memcache' not found in D:\xampp\htdocs\test\memcache\test.php on line 2
Line 2: $memcache = new Memcache;
Win7 64, Xampp Installed. I am using net start "memcached Server" on command line but it says service is already started.
Some other info which may help;
On php.ini file:
extension=php_memcache.dll
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211
Update: phpinfo(); show dll is not loaded. Tried several different dll files so far, didn't work. Also dll is located correct. It is in the right folder as it seems.
(P.S. Some may think there are possible duplicates about this topic but there is only 1 person who followed the same instructions and had same error in SO. That question has no answer or solution since march.)
I found the working dll files for PHP 5.4.4
I don't knowhow stable they are but they work for sure. Credits goes to this link.
http://x32.elijst.nl/php_memcache-5.4-nts-vc9-x86.zip
http://x32.elijst.nl/php_memcache-5.4-vc9-x86.zip
It is the 2.2.5.0 version, I noticed after compiling it (for PHP
5.4.4).
Please note that it is not 2.2.6 but works. I also mirrored them in my own FTP.
Mirror links:
http://mustafabugra.com/resim/php_memcache-5.4-vc9-x86.zip
http://mustafabugra.com/resim/php_memcache-5.4-nts-vc9-x86.zip
Add this to your php.ini:
extension="php_memcache.dll"
and restart apache
Memcached just uses standard text interface so its possible to use it without the module.
// connect
$link = fsockopen($host,$port,$errno,$errst,$timeout);
// set
$data = sprintf("set %s 0 %s %s\r\n%s\r\n",
$key,$expire,strlen($value),$value);
fwrite($link,$data);
$result = trim(fgets($link));
if ($result == 'ERROR') {
// :(
}
// get
$data = sprintf("get %s\r\n",$key);
fwrite($link,$data);
$line = rtrim(fgets($link));
if ($line != 'END') {
return rtrim(fgets($link));
}
So i have looked now for a solution. Here you can download some compiled extensions.
http://downloads.php.net/pierre/
The problem is that at the moment there is no memcache extension for PHP 5.4. this is the problem why your extension could not be loaded. You need the extension for the correct PHP version and Tead Safe for Windows.
So the easiest way is to work with PHP 5.3 if you need the extension.
The newest version of memcache is the version 3.0.6 but its a beta version you can see it here.
http://pecl.php.net/package/memcache
You could try to take the beta version and compile it with your windows system. But its a lot of work.
Also problem can be in loading another version of php module somewhere in apache .conf files. Need to check duplicated "LoadModule php..." directives and if that module compiled to correct version of apache.
It seems sound simply, but not when you have several versions of php on one machine :)
Or it can be SElinux problem too.
xampp windows version is 32bit ,you must be use 32bit memcache.dll
I hole that would be useful for you!

"Call to undefined .. mssql_connect" when using PHP in IIS?

May is ask you about how to connect to Microsoft SQL server 2005 enterprise using PHP.
I am using Appserv 2.5.10 ( Apache 2.2.8, PHP 5.2.6) and SQL server 2005
After I place the extension download from this link :
http://www.microsoft.com/en-us/download/details.aspx?id=20098
enable the php.ini file by adding these lines.
extension=php_pdo.dll
extension=php_sqlsrv_52_ts_vc6.dll
extension=php_pdo_sqlsrv_52_ts_vc6.dll
Restart Apache using this code to connect
$link = mssql_connect($server, $user, $pass);
Error shown in browser is
Fatal error: Call to undefined function mssql_connect() in G:\AppServ\www\testmssql_connect.php on line 12
can anyone help me ?
NOTE: i am using windows server 2003 and i don't found this OS in OS supporting list of Microsoft Driver 3.0 for PHP. Is this issue cause the problem ?
Look at this link:
PHP Fatal error: Call to undefined function mssql_connect()
1) Check your PHP.INI file's extension_dir
2) Make sure you copied your .dlls into that directory (for example, into C:\PHP\ext").
3) Create a dummy page to call phpinfo();. Display the page in a browser. Make sure you see entries for "sqlsrv".
'Hope that helps!

How to set up OCI to connect to Oracle from PHP?

On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI.
I've downloaded the "Instant Client Package - Basic Lite" (Link). I've unzipped the package containing the OCI libraries to a dir but I have no idea how to tell PHP that I want to use these libraries. Predictably, I get
Fatal error: Call to undefined function oci_connect() in...
when running this code:
<?php
$conn = oci_connect('hr', 'hrpw', 'someremotehost');
?>
I don't want to recompile PHP with Oracle support. What's the fastest way to wire up PHP so that I can use Oracle? Do I need any other libaries, like the Oracle client if I want to connect to a remote Oracle instance?
You need the PHP extension, try the following on your Ubuntu:
(sudo) pecl install oci8
Make sure your php.ini's (there should be one for your Apache and one for cli php) contain extension=oci8.so afterwards. Finally, you have to restart Apache and can confirm via <?php phpinfo(); ?> that the extension is loaded.
UPDATE:
Enter something like this when it asks you for ORACLE_HOME:
instantclient,/opt/oracle/instantclient
I think setting the environment variable would be another solution. /opt/oracle... is the path I put my instantclient in. I followed some tutorial a while ago, unfortunately I can't find it anmore.
HTH
I think you'll need to make sure that the $ORACLE_HOME/lib32 is in your $LD_LIBRARY_PATH, or else add that directory to the /etc/ld.so.conf file.
In the end, I downloaded Zend Core for Oracle and that worked.
http://www.zend.com/en/products/core/for-oracle

Categories