XAMPP PHP doesn't run mssql% functions

Alles, was PHP betrifft, kann hier besprochen werden.

XAMPP PHP doesn't run mssql% functions

Postby keyboardchimp » 17. January 2019 12:03

Hallo alle!
Leider ist mein Deutsch zu schwach, um mein Problem zu beschreiben, so muss ich English benutzen, weil mein Problem PHP betrifft.

I'm new to PHP and web servers, but I have a basic understanding of databases. I'm using MS SQL Server and trying to find out how to query one of my databases via PHP. Since I'd like to test all queries on my local machine first, I downloaded XAMPP. So now I need to establish a connection to my database, and PHP that comes with XAMPP doesn't seem to be able to run mssql_% functions as the server says this:
Fatal error: Uncaught Error: Call to undefined function MSSQL_CONNECT() in C:\xampp\htdocs\my_stuff\db_connection.php:6 Stack trace: #0 {main} thrown in C:\xampp\htdocs\my_stuff\db_connection.php on line 6


For reference, the syntax in the corresponding PHP file is as follows:
Code: Select all
<?php
$hostname = "MyPC\Username";
$username = "dbo";
$dbName = "test_db";

MSSQL_CONNECT($hostname,$username) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Database unavailable")

?>


What could be the issue? I assume my PHP just isn't configured to read mssql% functions. How do I fix this?
Thank you!
keyboardchimp
 
Posts: 4
Joined: 17. January 2019 11:47
XAMPP version: v3.2.2
Operating System: Windows 7

Re: XAMPP PHP doesn't run mssql% functions

Postby Altrea » 17. January 2019 17:00

Hi,

Please read the manual: http://php.net/manual/en/function.mssql-connect.php
Can you find the answer? It is not well hidden :lol:

Best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: XAMPP PHP doesn't run mssql% functions

Postby Nobbie » 17. January 2019 21:15

keyboardchimp wrote:Hallo alle!
Leider ist mein Deutsch zu schwach, um mein Problem zu beschreiben, so muss ich English benutzen, weil mein Problem PHP betrifft.


No problem about that - but why dont you simply use one of the highly sophisticated translators in the Internet like http://www.deepl.com or Google translate https://translate.google.com/ ??

keyboardchimp wrote:What could be the issue?


That took me less than 10 seconds to find out, from http://php.net/manual/en/function.mssql-connect.php

Warning
This function was REMOVED in PHP 7.0.0.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: XAMPP PHP doesn't run mssql% functions

Postby keyboardchimp » 18. January 2019 13:25

Thanks for the replies!
I understand why my request might seem ridiculous, however there's a good reason for that - I've never used a programming language in my life. So I don't even always know how to google things. However, there's this quite specific task that I need to accomplish - establish a connection to my database.

From that manual I conclude that the function I should use is this: http://php.net/manual/en/function.sqlsrv-connect.php
Unfortunately, it hasn't solved the issue. The function is still "undefined".

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\ryan_stuff\db_connection.php:6 Stack trace: #0 {main} thrown in C:\xampp\htdocs\ryan_stuff\db_connection.php on line 6


Might it be that I have to configure my database server or XAMPP?
I'd highly appreciate any help. Thank you!
keyboardchimp
 
Posts: 4
Joined: 17. January 2019 11:47
XAMPP version: v3.2.2
Operating System: Windows 7

Re: XAMPP PHP doesn't run mssql% functions

Postby Altrea » 18. January 2019 15:00

You need to install the sql driver API library and include the dll in your php.ini configuration file first.
All described in the manual: http://php.net/manual/en/sqlsrv.installation.php

But why do you want to use MSSQL and not the included MariaDB/MySQL?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: XAMPP PHP doesn't run mssql% functions

Postby keyboardchimp » 19. January 2019 17:28

Altrea wrote:You need to install the sql driver API library and include the dll in your php.ini configuration file first.
All described in the manual: http://php.net/manual/en/sqlsrv.installation.php

But why do you want to use MSSQL and not the included MariaDB/MySQL?


Thank for the further hints, but I'm still stuck.

I know using MySQL would solve the issue once and for all, but I'd like to use SQL Server, because all my databases are created with it. I'm just practicing implementing those databases on a website, but I oh well.

Here's what I've done thus far.

1) Since I need drivers for PHP Version 7.3.0, I got them at https://github.com/Microsoft/msphpsql/releases (Windows-7.3.zip)
There are four files in the folder.

2) I've placed all possible combinations of those files in C:\xampp\php\ext and added corresponding lines like "extension=php_pdo_sqlsrv_73_nts". Every time I changed a line, I restarted Apache.
I don't know if it matters, but I placed all the lines just under all the other extensions (the last on the list is "extension=shmop").

3) Then I've proceeded to http://localhost/dashboard/phpinfo.php, but there was no changes on this page. And my connection attempt results in the same error.

What might I be doing wrong? Please help.
keyboardchimp
 
Posts: 4
Joined: 17. January 2019 11:47
XAMPP version: v3.2.2
Operating System: Windows 7

Re: XAMPP PHP doesn't run mssql% functions

Postby keyboardchimp » 20. January 2019 08:26

I guess there might be other XAMPP users who are just beginning to explore this whole thing. So for those who might per chance stumble upon the same issue, the solution was simple. Even though my system is x64, I had to use drivers for x86(x32) that you can get at https://github.com/Microsoft/msphpsql/releases

Thank you everyone, and best of luck configuring your connection!
keyboardchimp
 
Posts: 4
Joined: 17. January 2019 11:47
XAMPP version: v3.2.2
Operating System: Windows 7


Return to PHP

Who is online

Users browsing this forum: No registered users and 16 guests