I need to connect to a MS SQLServer 2008 service from PHP on Ubuntu, and I would like to do so using PDO. I believe I have installed all the prerequisite libraries, and I am indeed able to connect using tsql on the command line and using mssql_connect() in code. I can't figure out what the proper DSN is, or if there are any additional PDO-specific configuration steps I am missing.
I am using the following DSN (where $db* variables are populated with their appropriate values):
odbc:Driver=FreeTDS;SERVER=$dbServer;DATABASE=$dbSchema;UID=$dbUser;PWD=$dbPasswd"
My error message is:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /home/timothy/test.php:4
Stack trace:
#0 /home/timothy/test.php(4): PDO->__construct('odbc:Driver=Fre...')
#1 {main}
thrown in /home/timothy/test.php on line 4
What additional configuration steps have I over looked?
Thanks in advance.
You shouldn't need any additional configuration if you can connect with tsql and the mssql extension. You probably just don't have the correct dsn. This documentation should help. Try new PDO("dblib:host=xx.xx.xx.xx;dbname=mydatabase", "username", "password");
Related
Trying to connect to oracle 19c from php the server is not on the same machine as the php, I have so far installed instant client 19_15, added it as a environment variable, and then in the php.ini file I have taken off the semi colon for both the files extension=oci8_19 and extension=pdo_oci not sure what else to do to make the php to connect to the oracle db.
some error messages I have been getting are: PDO: connection failed: could not find driver
and from oci_connect: Fatal error: Uncaught Error: Call to undefined function oci_connect() in Stack trace: #0 {main} thrown in on line 7
p.s. architecture is x64, php version is 8.1.8 and using apache24 lounge
I'm using odbc and XAMPP. I'm receiving the fatal error of could not find driver
Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\index.php:5 Stack trace: #0 C:\xampp\htdocs\index.php(5): PDO->__construct('odbc:BEGIN') #1 {main} thrown in C:\xampp\htdocs\index.php on line 5
This is the code the error refering to :
$conn = new PDO ("odbc:BEGIN");
Is there any module that I should add to the php.ini like this answer or there are other solution?
You need to enable those extensions in order to have ODBC PDO driver working
php_pdo.dll
php_odbc.dll
php_pdo_odbc.dll
After enabling those extension as #Sarhan said, we need to restart Apache in order for it to work.
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 connect to a Foxpro database using the OLE DB Driver
I downloaded the driver from http://www.microsoft.com/en-us/download/details.aspx?id=14839 and installed it then create a php script
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("Provider=vfpoledb.1;Data Source=C:\Opera3\Comp_I.DBC;Collating Sequence=machine");
This gives me the following error
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> ADODB.Connection<br/><b>Description:</b> Provider cannot be found. It may not be properly installed.' in C:\inetpub\wwwroot\test1.php:4 Stack trace: #0 C:\inetpub\wwwroot\test1.php(4): com->Open('Provider=vfpole...') #1 {main} thrown in C:\inetpub\wwwroot\test1.php on line 4
Any help in getting this working would be much appreciated.
As requested
uninstalled and reinstalled from command line as administrator for all users and now it works –
I have installed PDO_INFORMIX and CSDK already on CentOS5.6 32bits
and index.php have
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$db = new PDO("informix:host=172.30.179.81; service=5000;database=cms; EnableScrollableCursors=1", "myuser", "mypassword");
print("OK");
?>
but i still got this error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE=HY000, SQLDriverConnect: -11060 [Informix][Informix ODBC Driver]General error.' in /usr/local/apache/htdocs/index3.php:5 Stack trace: #0 /usr/local/apache/htdocs/index3.php(5): PDO->__construct('informix:host=1...', 'myuser', 'mypassword') #1 {main} thrown in /usr/local/apache/htdocs/index3.php on line 5
Have anyone know what it is ?
Thanks
Ouch! The standard technique for finding out more about errors is:
$ finderr -11060
-11060 General error.
An error occurred that has no specific SQL_STATE. In this case,
additional text is provided that identifies the source of the problem.
This IBM Informix CLI error code is the same as SQLSTATE value S1000.
$
That is not very helpful - to be polite about it.
There are spaces in the connect string; does removing them help at all?
Can you telnet to the host 172.30.179.81?
Can you telnet to the port (service) 5000 on the host?
Can you connect from this machine using any other Informix tool?
Can you connect from other machines using the same connect string?
In case of desparation, can you track down whether all the shared libraries are loading correctly?