So I have a trouble here. Tried use mssql_connect() but interpeter says that function is undefinied. PHP.net advices this, but it suppports only older versions of PHP. Is it possible to connect to MS SQL Server database from PHP5.6? What extensions should I add, what functions can I use?
Configuration details: localhost, Apache 2.4, PHP 5.6, OS Windows 8.
You need to enable the MSSQL extension in the PHP.ini file.
If this extension is not installed, you need to install it in PHP.
Please tell your server details (OS/WebServer like apache nginx) so that I can explain in detail.
Use
<?php phpinfo();?>
to see what are available with your php installation. I advice you to use PDO instead of mysql_* functions. It supports several databases not only MSSQL or MySQL.
Related
I have the latest version of Apache (Apache 2.4), latest version of PHP (PHP7), and latest version of MySQL (not sure the version but I have WorkBench version 6.3). In the past, when I checked if my PHP was working by this line of code <?php phpinfo(); ?> it would show that I have MySQL / mysqli installed and ready to go. But with PHP7 it shows mysqlnd.
I try using mysqli commands to check if I can connect to my database by mysqli_ping() and I also tried connecting to the database using server, user, pass. I keep getting errors such as Class mysqli not found. Or Call to undefined function mysqli_ping(). I've tried searching the net for some answers and All I could find was that I need to install MySQL (but a few sites said it was deprecated).
Am I able to get mysqli for PHP7? Or do I use mysqlnd? What is mysqlnd? Is it a new version of MySQL/mysqli?
Update 2020
For Windows 10 users I strongly recommend windows subsystem for linux (WSL 2) and setup your server there.
If you need php and mysql access in windows environment, then the fastest way is to install Wampserver. If you also need access to php through console then add php location (like C:\wamp64\bin\php\php7.4.11) to environment variables.
If that doesn't suit you and you need full setup always enabled on your system then follow install with choco.
To work properly with apache and load all needed extensions (including php_mysqli) you need ThreadSafe version of PHP, so make sure to download correct version or if you use Chocolatey to manage your windows applications, then just install php with this command:
choco install php --package-parameters='"/ThreadSafe "'.
This will install php in C:\tools\php72 directory, but you can overwrite it with another parameter:
choco install php --package-parameters='"/ThreadSafe ""/InstallDir:C:\PHP"""'.
The mysqlnd extension is part of PHP. It was developed as an alternative to bundling the libmysqlclient, because that library had license conditions that made it awkward to bundle with PHP.
You won't use mysqlnd directly. It's an internal library that is used by mysqli and pdo_mysql as a means to communicate with the MySQL Server.
As for mysqli, yes, it's available for PHP 7. I don't use Windows, but apparently not all extensions are enabled by default.
You probably need to edit your php.ini and uncomment the line
extension=ext_mysqli.dll
or whatever it is for that extension. It might already be in the file, but commented out. So go take a look and see.
Check if your system path environmental variable includes the PHP installation directory. That worked for me on with PHP 7.1 / Apache 2.4 / Windows Server 2016.
I'm using xampp-win32-1.8.3-1-VC11-installer and i enabled php_mssql.dll extension in php.ini by remove ;
I copy php_mssql.dll to xampp\php\ext
and ntwdblib.dll to xampp\apache\bin
i got 2 files above in old of xampp version.
But when i start my apache in xampp then i get
How to fix that thanks
It announced from php website http://php.net/manual/en/intro.mssql.php
These functions allow you to access MS SQL Server database.
This extension is not available anymore on Windows with PHP 5.3 or later.
SQLSRV, an alternative extension for MS SQL connectivity is available from Microsoft: ยป http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx.
Since XAMPP 1.8.0 its used PHP 5.4.4 and php_mssql.dll extension is not available anymore on windows with PHP 5.3 or later.
So you can't use this library to your new XAMPP although you get it from your old XAMPP.
You must use alternative extension to connect to MS SQL Server database like SQLSRV.
See also ::
http://php.net/manual/en/intro.mssql.php
http://stackoverflow.com/questions/7402713/how-to-get-mssql-work-with-php-5-3
Your php version from XAMPP 1.8.3 is PHP 5.5.15, so you must use "php_sqlsrv_55_nts.dll" or "php_sqlsrv_55_ts.dll". Those files can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20098`.
Note :: see also the information on Details section to help you choose file that you must download
This link about documentation to code with sqlsrv library
http://php.net/manual/en/book.sqlsrv.php
Windows PHP extensions are neither forward nor backward compatible between second-level PHP versions. That means you cannot use a PHP 5.3 extension in PHP 5.4 and vice-versa.
As you're running XAMPP 1.8.3 and this is one of the first PHP bundles with the VC11-PHP5.5 builds you'll have to find a VC11-PHP5.5 compatible extension somewhere else.
I've just checked another WAMP bundle called EasyPHP, but they don't ship the MS SQL extension with their VC11-PHP5.5 bundle either.
I can't help with finding a compatible extension, though.
You could also build the extension yourself if that is an option for you.
I have installed Apache2.2 and then installed PHP5.4.8. I cannot get my new .php file to load in a browser because it keeps giving me the error Fatal error: Call to undefined function mysql_connect(). When I load the test.php file which has only this in it:
<?php phpinfo(); ?> it returns a page that shows information about PHP but where it would show the MySQL modules it only shows mysqlnd. What is that? Also, I have gone through the php.ini file and uncommented the proper lines for MySQL integration as well as having edited the Apache2.2 httpd file. Does anyone have any answers as to why MySQL isn't working? Thanks in advance.
Also, Ive tried many of the solutions from this website as well as many google searches. I can't seem to figure it out. :-(
1) Have a look on choosing MySQL API. It is recommended to use mysqli extension.
2) According to Other changes to extensions, the MySQL extensions mysql, mysqli and PDO_mysql use mysqlnd as the default library now.
A quote from MySQL Native Driver - mysqlnd site:
Although MySQL Native Driver is written as a PHP extension, it is important to note that it does not provide a new API to the PHP programmer. The programmer APIs for MySQL database connectivity are provided by the MySQL extension, mysqli and PDO MYSQL. These extensions can now use the services of MySQL Native Driver to communicate with the MySQL Server. Therefore, you should not think of MySQL Native Driver as an API.
That means, the mysqlnd extension does not export any function you can use in your scripts, but acts as a bridge between your code and one of mysql, mysqli, pdo_mysql extensions.
You mentioned, that phpinfo() shows only mysqlnd. The fact you don't see section titled MySQL there means that mysql extension is not enabled (commented out) in php.ini (Windows) or your php is not compiled with mysql support (Linux). More details about installing MySQL extension are here.
What is your OS?
To have a successfull MySQL connection you should:
Install the MySQL Server
Configure the PHP to use the proper mysql socket: (in php.ini search for mysql.default_socket - point it to the mysql server).
Reboot the web server - Apache
I am currently trying to connect to my localdb on MSSQL 2012 Express.
I have downloaded and installed the official microsoft driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098
I get some kind of SQLSRV section in my phpinfo(). But when I try to create a new PDO object it says it does not have the driver. Which I could understand since it is not mentioned on the phpinfo() PDO section, but it has its own section + the get_loaded_extensions also shows sqlsrv. I suppose thats from the official MS Driver ? I am using the php_sqlsrv_53_nts.dll
With my Zend Server CE 5.6 with PHP 5.3.9
Now as far as I understood I downloaded the wrong driver and should try the one that is brought by the PECL manager? There is only the sourcecode available and obviously I am on a windows machine so I can forget about everything that I need to compile myself - I am actually getting the suffix errors when using the powershell and my pecl / pear installation.
Has anybody solve that problem ? Any help much appreciated
All the best,
Richard
The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable
extension=php_pdo_mssql.dll
in your php.ini.
Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/ and just take the extension from a package there (take one that correspond with your PHP version of course).
//edit: just read you latest comment. This extension is available for a very long time now and can be considered working. If you are not allowed to use it you must rewrite your code to use the functions the native driver offers for PHP.
Another possibility is to use the odbc drivers which are by default included in the php extensions, you still might have to uncomment them in your php.ini though.
extension=php_pdo_odbc.dll
Don't forget to restart your server afterwards ;-)
And then use it like this:
$db = new PDO('odbc:Driver={SQL Server};Server=192.168.x.x;Database=DatabaseName; Uid=User;Pwd=Password');
$stmt = $db->query("SELECT the_usual FROM aTable WHERE all='well'");
Alright. I suppose its just one of these days.
I got the wrong extension loaded from the supplied ones by MS. I needed to use php_pdo_sqlsrv_53_nts
rather than
php_sqlsrv_53_nts
Thanks for all the help
I've been struggling with this for a while now and I don't know what I'm missing. The error is:
call to undefined function mssql_connect()
Having looked into it already, I've done about everything I can.
I moved the php.ini file to c:\windows
In the ini I changed the extension_dir directive to c:PHP\ext and uncommented:
extension = php_mssql.dll
I moved the dll file to c:windows\system32\
I downloaded the 200.80.194.0 version of ntwdblib.dll and placed it in c:\windows\system32
I restarted my web server client
PHP is still not recognizing the function and library classes. I'm stumped as to what I didn't do right and would love some help. If it's helpful, I'm running PHP 5.3.2, IIS, and Microsoft SQL Server 2008.
For SQL Server 2008 on Windows it's sqlsrv_connect This is because Microsoft now uses the SQL Driver for PHP which is now on version 2.0 I believe.
Also it's worth noting that with sqlsrv_query, and mssql_query they switched the parameters around (spent half an hour figuring that out).
You say you are running PHP 5.3.2. The PHP manual states:
This extension is not available anymore on Windows with PHP 5.3 or later.
The PHP MSSQL library is ancient and is no longer considered a viable option.
You should instead examine PDO with either the MSSQL driver or the more reliable ODBC driver.
Microsoft are still developing their own PDO driver. Version 2 was made available June 2010. Microsoft recommend the more stable version 1.1 for production use.