I'm trying to put together a page that can submit data from a form to an MSSQL database via PHP. I've got PHP installed successfully (phpinfo() runs fine even on a remote computer) but it will not load the sqlsrv extension. I know that I'm editing the right php.ini file because I have another extension added (wincache) and it is loading fine, confirmed with both phpinfo() and get_loaded_extensions().
The logs aren't telling me anything. PHP Manager on IIS is telling me that the sqlsrv extension files are enabled. I've restarted the website, the server, and the computer, and nothing's working.
I'm using PHP 7.1.1 on a Windows 7 Ultimate machine. It's running in x64 mode, Non-Thread Safe. I've made sure that the extension files I enabled are the x64, non-thread-safe ones. I don't know what else to check or what more info I need to provide.
EDIT: I ran php-cgi.exe as this page suggested, and it came out with the error mesages:
[31-Mar-2017 22:38:12 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\iis express\PHP\v7.1\ext\php_sqlsrv_7_nts_x64.dll' - The specified procedure could not be found.
in Unknown on line 0
[31-Mar-2017 22:38:17 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\iis express\PHP\v7.1\ext\php_pdo_sqlsrv_7_nts_x64.dll' - The specified procedure could not be found.
in Unknown on line 0
Does this mean that the problem is in the extension DLLs themselves? How would I even go about fixing that?
EDIT 2: ImClarky nailed the problem in that I was apparently using a way outdated version of the extension. I've got it working, but now my authentication is failing for reasons I don't understand:
function connect_sql() {
/* Specify server and connection attributes */
$serverName = "(local)";
/* Get UID and PWD from app-specific files */
$uid = file_get_contents("C:\AppData\uid.txt");
$pwd = file_get_contents("C:\AppData\pwd.txt");
$connectionInfo = array("UID" => $uid,
"PWD" => $pwd,
"Database" => "database_name");
/* Connect using SQL Server Auth */
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false)
{
echo "Unable to connect.</br>";
//die(print_r(sqlsrv_errors(), true));
die(print_errors());
}
else {
echo "Connection Successful";
}
/* Free connection resources */
sqlsrv_close($conn);
}
I've double checked that I am using the correct username and password, and I even went in and created an entirely new login using the exact UID and password I'm trying. I still get the following error message every time:
Unable to connect.
SQLSTATE: 28000
code: 18456
message: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'username'.
SQLSTATE: 28000
code: 18456
message: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'username'.
Make sure you add .dll file for extension folder used by php.ini
Also chose correct driver of SQLSRv matched your running PHP
SQLSRv sqlsrv from official microsoft page
Related
I am attempting to set up a website on my Windows 10 machine using IIS. I can successfully load a simple php file (using PHP 8.1).
When I attempt a new PDO call to MSAccess I get:
HTTP Error 500.0 - Internal Server Error
C:\php\php-cgi.exe - The FastCGI process exited unexpectedly
My code is
$dbName = $_SERVER["DOCUMENT_ROOT"] . "\\vhs\VHS.accdb";
try {
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$dbName;Uid=admin;");
}
catch (PDOException $e) {
echo $e->getMessage();
}
Nothing gets placed into the php_errors.log.
I have both
extension=pdo_odbc.dll
extension=php_pdo_odbc.dll
in my php.ini file (and both exist in the ext folder).
I have tried the following:
1 - a different MSAccess database (both another .accdb and an old .mdb) ... same error
2 - using the incorrect driver name (for example "Microsoft Blah Driver") ... this results in a PDOException "SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" so I believe I have the driver spelled correctly in my original code
The Microsoft Access Driver (*.mdb, .accdb) name matches the one I see in the 64-bit ODBC administrator. If I instead use Microsoft Access Driver (.mdb) which appears in the 32-bit administrator I get the 'Data source name not found' error as well.
Does anyone have any suggestions for things to check / try?
This is the output from phpinfo()
im trying to establish an Database Connection to an Oracle Database. But i get the following issue:
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries in C:\xampp\htdocs\TanWLSI\Login.php on line 6
I have set the php.ini Extension for OCI:
extension=php_oci8_12c
This is the output from phpinfo()
Did i need an ORACLE_HOME Variable ?
I have installed PHP 5.6.30 64 bit on Windows Server 2012 along with Teradata ODBC driver.
Whenever I test the PHP connection I receive an error
Warning: odbc_connect(): SQL error: Specified driver could not be loaded due to system error 126: The specified module could not be found. (Teradata, C:\Program Files\Teradata\Client\15.00\ODBC Driver for Teradata nt-x8664\Lib\tdata32.dll)., SQL state IM003 in SQLConnect
EDIT: C:\Program Files\Teradata\Client\15.00\ODBC Driver for Teradata nt-x8664\Lib\tdata32.dll does definitely exist on that specific path. Also, using tdxodbc.exe to test the ODBC connection works normally using tdata32.dll, so it appears to be some issue with PHP.
I have installed Teradata ODBC via GSS > ICU > ODBC from the Utilities package based on a related thread however still experiencing the same error. I can make a successful 32-bit ODBC connection via SQL assistant. I have tried a DSN / DSN-less ODBC connection via PHP but same error occurs.
I have been unable to find any clear indication of what the issue is - any idea?
I'm updating a application to stop using 'mssql_connect' to use PDO with ODBC for PHP 7.
Locally, I'm using XAMPP on Windows 8 and my application works fine. However, when I upload it to the Ubuntu server (Locaweb hosting, in Brazil) it returns the following error:
PDOException: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified in /public_html/user/log-connections/connection.php:28 Stack trace: #0 /public_html/user/log-connections/connection.php(28): PDO->__construct('odbc:Driver={SQ...') #1 /public_html/user/log-connections/login.php(2): require_once('/public_html/user...') #2 {main}
The line causing the error (connection.php:28) is this one:
$pdo = new PDO("odbc:Driver={SQL Server}; Server={$servername}; Database={$dbname};", $username, $password);
I already tried using other driver names, such as "SQL Server Native Client", "FreeTDS", etc. But all returns the same error. Another thing is that the SQL Server isn't on the same server.
The solutions that I found on my research was telling me change the odbc.ini file and other files. But, I don't have access to those file on the server. Besides, on my local, I didn't change none of those files, just extended the modules to activate PDO and ODBC on the PHP.
Also, I already checked the phpInfo and the PDO and ODBC are enabled with "PDO Driver for ODBC (unixODBC)".
Anyone have experienced this kind of problem?
I'm attempting to connect with a Sybase database with PHP7 on Windows Server 2012 R2 using the sqlsrv PDO driver. I've tried a number of connection strings - the following is the most direct connection string I've found that should be at least tossing me an error (an error from PHP) when accessing the page. However, when I access the page it it tells me the page is not working (as in the PHP is not working). PDO SQLSRV is active in my phpinfo(). The PHP Error I receive is:
[18-Nov-2016 22:32:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\v7.0\ext\php_wincache.dll' - The specified module could not be found.
in Unknown on line 0
And many times in the same log file I am receiving the following error:
[18-Nov-2016 22:31:23 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\v7.0\ext\php_mysql.dll' - The specified module could not be found.
in Unknown on line 0
This is all basically a straight-up install, so I'm surprised that it's tossing back errors about windows cache and mysql (when I'm not even attempting to access a mysql anything). Any leads or information would be great. Thank you for this forum!
<?php
try {
$server_name = "MY\SERVER,1234";
$database_name = "myDatabase";
$username = "myUsername";
$password = "myPassword";
$conn = new PDO("sqlsrv:server=$server_name;database=$database_name", "$username", "$password");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e ) {
die( "Error connecting to SQL Server" );
}
echo "Connected to SQL Server\n";
?>