As the title says, I'm having issues connecting to MSSQL from a PHP Script.
The setup:-
PHP is running on an Apache Linux Server.
Microsoft SQL Server 2008 is on an XP Machine.
I've got Remote Connections turned on in the MSSQL Server.
The database bggs does exist.
The database is running (I can see a green arrow).
I have no firewall on the XP Machine.
If you have any debugging questions, don't hesitate to ask.
I'm using the following test script.
<?php
include('adodb5/adodb.inc.php');
$db =& ADONewConnection('odbc_mssql');
$db->debug = true;
$dsn = "Driver={SQL Server};Server=ozmodiar;Database=bggs;";
$db->Connect($dsn,'user','password');
$rs = $db->Execute('select * from admin_users');
print "<pre>";
print_r($rs->GetRows());
print "</pre>";
?>
Getting the following result.
Warning: odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/adodb5/drivers/adodb-odbc.inc.php on line 60
(odbc_mssql): SET CONCAT_NULL_YIELDS_NULL OFF
Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/adodb5/drivers/adodb-odbc.inc.php on line 530
IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ADOConnection._Execute(SET CONCAT_NULL_YIELDS_NULL OFF, false) % line 1017, file: adodb.inc.php
ADOConnection.Execute(SET CONCAT_NULL_YIELDS_NULL OFF) % line 62, file: adodb-odbc.inc.php
ADODB_odbc._connect(Driver={SQL Server};Server=192.168.70.130;Database=bggs;, sa, knd121, ) % line 524, file: adodb.inc.php
ADOConnection.Connect(Driver={SQL Server};Server=192.168.70.130;Database=bggs;, sa, knd121) % line 9, file: test_db.php
Driver={SQL Server};Server=192.168.70.130;Database=bggs;: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
(odbc_mssql): select * from admin_users
Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/adodb5/drivers/adodb-odbc.inc.php on line 530
IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ADOConnection._Execute(select * from admin_users, false) % line 1017, file: adodb.inc.php
ADOConnection.Execute(select * from admin_users) % line 10, file: test_db.php
Fatal error: Call to a member function GetRows() on a non-object in /mnt/filestore/vhost/bggs/hr_database/Dev/includes/test_db.php on line 12
Disclaimer: I've only queried data from Microsoft SQL Server 2000, but through PDO_DBLIB although I believe the pre-requisite of having freetds drivers for either ADODB or PDO_DBLIB a certainty.
Judging by the initial error message, you do not have necessary drivers installed. In order for your application to access the server, you will need to install freetds, which will install the necessary drivers and allow you to set up the the ODBC connections. Check out: http://www.linuxjournal.com/article/6636
It's important to note that you need to set the "tds version = x.x" in your freetds global config or specific OBDC connection (/etc/freetds/freetds.conf by default on debian) exactly right, or the protocol freedtds uses with your server will not be correct and the script will bomb.
Related
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
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 trying to fetch data from access db in php. Code works fine for 32 bit php( I've tested in php version>5), but code generates error for 64bit php wamp.
Error Message: Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in
What I've tried : How can I correct this error: Data source name not found and no default driver specified
Code :
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$db", "","");
$tabs = odbc_tables($connection);
Is there any solution or I've to install 32 bit version?
Microsoft Access Driver (*.mdb)
refers to the older Access "Jet" driver which is installed as part of Windows itself but is only available to 32-bit applications. (There is no 64-bit version of Jet.)
You could download and install the 64-bit version of the newer Access Database Engine (a.k.a. "ACE", available here) and then use
Microsoft Access Driver (*.mdb, *.accdb)
as the driver name. (Assuming that the WAMP server does not already have a copy of Access 2007 or later installed on it.)
I am trying to use ODBC with php and I seem to be having some problems. This is my code:
<?php
$connect = odbc_connect("digitallibrary", "root", "");
$sql = "SELECT name FROM books";
$result = odbc_exec($connect, $sql);
echo $result;
while (odbc_fetch_row($result)) {
$name = odbc_result($result, "name");
print("$name\n");
}
odbc_close($connect);
?>
I have also installed mysql odbc connector and added this system DSN:
Datasource Name : digitallibrary
TCP/IP Server: localhost Port 80
user: root
database:digitallibrary
When I run my code I get this warnings but nothing printed:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 9
Warning: odbc_exec() expects parameter 1 to be resource, boolean given
in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 11
Warning: odbc_fetch_row() expects parameter 1 to be resource, null
given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on
line 14
Warning: odbc_close() expects parameter 1 to be resource, boolean
given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on
line 18
what am I doing wrong?
Now, You are attempting to use a 64 bit application with a 32 bit ODBC driver or vice versa. You should check that what are you using the PHP application 64 bit or 32 bit. After that you have to start the correct ODBC administrator. There are 2 types which are 32 bit and and 64 bit.
If you are using 64 bit ODBC administrator: It is in Adminstrative tools, control panel
If you are using 32 bit ODBC administrator: You should go into the path %windir\syswow64\odbcad32.exe.
When you have set the right ODBC administrator. You will also need to create the system DSN. If you cannot find the MS Access driver in the administrator you'll need to download one for that architecture.
EDIT : you can download the 32 bit from here
Hope this helps.