Getting mssql_connect() error even though I have the drivers - php

this is something I've really been losing sleep over, so I'd be very thankful if anyone could help me.
So, I'm trying to set up a launcher for a game. I have a Login.php on my web server and the launcher in Visual Studio. When pressing "Start" it connects to Login.php where it checks if the game login credentials are correct, if they are, it should return a string of random letters (a token) to the Launcher. The Login.php tries to connect to my database in SQL Server 2008.
Now to the problem, I get
Fatal error: Call to undefined function mssql_connect() in C:\inetpub\wwwroot\Login.php on line 12
when trying to go to the website manually (By entering 127.0.0.1/Login.php into the browser.). And when I try to run the program and press start, it returns a 500 Internal Error.
I have googled the mssql error and found out that the mssql functions have been removed from the newer versions of PHP, so I downloaded the drivers from Microsoft and enabled them in the PHP Manager on IIS 7.5.
The version of PHP I use is 5.4.25 and I enabled these drivers:
php_pdo_sqlsrv_54_nts.dll
php_sqlsrv_54_nts.dll
And here are the first 13 lines of the Login.php:
<?php
$conf['db_host'] = "GERA044\SQLEXPRESS";
$conf['db_user'] = "sa";
$conf['db_pass'] = "L4sfa445AdxDDLfor95";
$conf['db_name'] = "Account";
$user = sql_clean($_GET['Username']);
$passhash = sql_clean($_GET['Password']);
$con = mssql_connect($conf['db_host'],$conf['db_user'],$conf['db_pass']) or die('Database connect Fail.');
$db = mssql_select_db($conf['db_name'], $con) or die('Database Init Fail.');
In short: I still get an mssql error even though I have the drivers.
Hopefully someone can find a solution to the problem here,
Thank you!

php_sqlsrv_54_nts.dll is the SQLSRV extension, not the MSSQL one. You should use the sqlsrv_* family of functions instead of the mssql_* one.

Related

PHP to Azure SQL Server Undefined Function sqlsrv_connect

I've been trying to connect to my Azure SQL database using PHP 7.1. I've been following Microsoft's instructions so I'm using the iis express. After browsing and following the directions from posts like "Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP and
Cannot Call function sqlsrv_connect(), I still cannot connect.
<?php
$serverName = "database_name.database.windows.net";
$connectionOptions = array("Database" => "database_name");
try {
$conn = sqlsrv_connect($serverName, $connectionOptions);
} catch (Exception $e) {
print_r($e);
}
?>
Here are the solutions I've tried:
Installed all the necessary SQL drivers
Reconfigured the php.ini file with the extensions and correct extension path
Ran PHP as an administrator from the PHP folder and also from another folder using its %PATH%
Restarted several times
Connected successfully to the database from the CMD line
This is my first time using PHP to connect to a remote SQL server so any help would be greatly appreciated.
You need to check whether your drivers match the PHP Version, Architecture (32/64 bits) and Thread Safety you are using.
For example, if you are using x86 and thread-safe version of PHP 7 then the following DLLs should be used:
extension=php_sqlsrv_7_nts_x86.dll
extension=php_pdo_sqlsrv_7_nts_x86.dll
You can see these PHP info via phpinfo() function:

Installing drivers for SQL Server in PHP

I'm new to PHP. PHP is installed and working, and now I'm trying to set up connection with a SQL Server DB. Following instructions from a Youtube video. Went through and finished installing the drivers, but it isn't working. My test page stops running code after the sqlsrv_connect() function is called. I'm not even getting an error message. Below is my test page code:
<?php
echo '<br><span style="font-weight:bold;">PHP functioning. This line is being echoed out.</span><br />';
/*No problems yet...*/
$serverName = "Myserver";
$connectionInfo = array('Database'=>'nde', 'UID'=>'sa', 'PWD'=>'!hegEcu&3ATr');
$conn = sqlsrv_connect($serverName, $connectionInfo);
/*Nothing is appearing on the screen after this */
echo 'Still working...<br />';
if ($conn) {
echo 'Connection established.<br />';
} else {
echo 'Nope.<br />';
die(print_r(sqlserv_errors(), TRUE));
}
?>
I'm running PHP 7.0.21, and SQL Server 2014. I went and downloaded the two DLL files I think I need - php_pdo_sqlsrv_7_ts_x64.dll, and php_sqlsrv_7_ts_x64.dll. I copied them to Program Files/PHP/v7.0/ext. I went into PHP.ini as admin, and typed:
extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x64.dll
in the Windows Extensions sections. I saved PHP.ini, restarted both the IIS Admin Service and World Wide Web Publishing Service, and went into IIS Manager and restarted the server. PHP is still working, but I'm still not getting any echo after the sqlsrv_connect() call.
Okay, I got it working. As ctwheels suggested, i just installed the nts driver versions instead of the ts versions, which are php_pdo_sqlsrv_7_nts_x64.dll and
extension=php_sqlsrv_7_nts_x64.dll. It's working with sqlsrv_connect(); I haven't tried using PDO. I'm new to PHP and unfamiliar with PDO, but I'll probably come across it again, especially as I start looking into PHP frameworks (Cake and CodeIgniter).
One important thing to share for anyone who might also be new to PHP - the PHP documentation says that the $serverName argument of sqlsrv_connect() should be in the format of servername/instancename. So I used this query to get both: select ##servername + '\' + ##servicename, and got "Myserver\MSSQLServer". However, using this as the $serverName argument caused the connection to fail. Only after I took out "\MSSQLServer" did it connect successfully. So as in the code above, the correct value to use was $serverName = "Myserver".

Cannot connect to MySQL Database with MDB2 (Error not Found)

In first point. I am absolutely a noob in PHP and PEAR. For exercising I have worked with PHP, Pear and Mondial DB of Oracle offline, but now I wanted to connect to my Database on 1and1.com.
Following I have tried:
$dsn = 'mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx'; //Have it tried with password too and many other variations
$sql = "SELECT * FROM Vereine";
$db = MDB2_Util::connect($dsn);
If I upload this file on my webserver and when I try to call this page, I get an error.
Fehler beim Verbindungsaufbau mit [mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx] : MDB2 Error: not found
The error Message:
"Fehler beim Verbindungsaubau" is an own deinied Message in MDB2_Util.
If I try to connect with MDB2::connect, then the Message calls only:
MDB2 Error: not found
What can be the Error? Why it doesnt show the real Error or a helpful hint. Can I debug? If yes, how?
Best Regards Benny
This can occur even if you have installed an MDB2 driver, but PHP can't find or can't read it.
As a practical example, I experienced this problem on a system on which the UMASK value had been changed from 022 to 027. Even though the MDB2 driver had been installed (with root privileges), the user under whom php-fpm was running lacked access to the library's files.

mysqli not working, module not found

I am new to PHP and web servers, and i was going to make a website using PHP. I found a free login script that uses mysqli. Every time I go on the page it says I don't have mysqli? I am running Apache with PHP3. The mysqli part of the script is thus:
// if the connection is successfully established
if($conn = new mysqli($this->conn_datas['localhost'], $this->conn_datas['daztestc_testdaz'], $this->conn_datas['dj2403ms81'], $this->conn_datas['daztestc_daztest'])) {
$sql = "SET NAMES 'utf8'";
$conn->query($sql);
$this->conn = $conn; // add the connection in the $conn property
}
php3? mysqli was not introduced until php5. where did you find a server with such an old copy of php? and is any of the code working? as most things have changed since php3.
Probably you don't have MySQLI extension installed. Check this page to know how to enable it. Ah... of course... you can't use it on PHP3... so if you really want, upgrade your server.

mssql_connect() with PHP5 and MSSQL2012 Express

I'm having heavy issues trying to connect to my MSSQL 2012 Express database, with PHP5 running on an Apache.
I have as a test setup just installed a XAMPP with PHP 5.4.4 and Apache running on a Windows 7 machine.
My PHP code (phpmssql_genxml.php):
$connection = mssql_connect('192.168.40.150', $username, $password);
if (!$connection) { die('Not connected : ' . mssql_get_last_message());}
$db_selected = mssql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mssql_get_last_message());
}
$query = "SELECT * FROM Cust WHERE 1";
$result = mssql_query($query);
if (!$result) {
die('Invalid query: ' . mssql_get_last_message());
}
Output when trying to enter the site:
Fatal error: Call to undefined function mssql_connect() in C:\xampp\htdocs\phpmssql_genxml.php on line 13
Even if I try to hardcode the username and password into the string, I still get the same result.
Have search a lot on google, but havn't found that post that fixed my issue yet :/
Have enable TCP/IP for the DB instance pipe, even try'd to assign a specific TCP port for it. Have created a rule in the Win7 firewall allowing all traffic to the standard port 1433. Still no luck.
any1 have an idea?? What does the 'Fatal error' part means? Is it the Apache error, PHP or a Database error when trying to connect to it??
You are missing MSSQL driver from your PHP setup. Download it from here, assuming you have the required system configuration mentioned on the page.
Setting up, from their instructions:
Download SQLSRV30.EXE to a temporary directory
Run SQLSRV30.EXE
When prompted, enter the path to the PHP extensions directory
After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps
I would also recommend using standard Apache + PHP installation, if you plan to work with MSSQL, instead of any *AMP package.
You don't need to use SQLSRV30 as this was not the solution that I needed though some may find it useful. I have a local dev environment running XAMPP + php5.5.9 + MSSQL2012 and I needed to use mssql functions because thats what we use at work on our servers. So I use freetds and "luckily" found this:
https://moodle.org/mod/forum/discuss.php?d=232844
where one of the users already compiled the php_dblib.dll TS and NTS for my php version suffice to say I have everything working and using all the MSSQL functions that our dev team is used to. The extension for mssql support can always be compiled.

Categories