it has been days (weeks ?) since I try to connect to an Informix SQL database with PHP but I can't make it work.
I'm stuck with this error :
SQLSTATE=HY000, SQLDriverConnect: -329 [Random characters, ex :`�%]
sqlerrm(systables)
I can make the link with Windows ODBC utility http://i.stack.imgur.com/1ChAL.png
But impossible on PHP.
I installed the informix drivers and the informix dll extension for php and run it like this:
putenv("INFORMIXDIR=C:\\informix");
try {
$db = new PDO("informix:host=iat-----; service=sqlexec; database=sige---; server=iat-----; protocol=sesoctcp;", "if----", "pass---");
} catch (Exception $e) {
echo('Erreur : ' . $e->getMessage() . '<br>');
}
Thank you for your kind help.
Error message -329 is:
Database not found or no system permission
It means that despite your best efforts, something is astray with the environment. Either you've misspelled the database name or the server name, or the database is not set up to allow the user access to the database, or something along those lines.
Much more than that, I can't help you with. You're on Windows, and I'm not. You can look at the SETNET32 settings, but the fact that you can connect via the Windows ODBC utility suggests that most of what you need should be OK.
To fix this, you must restart the services for apache and php. If you are in linux, you can use the command "/etc/init.d/httpd restart"
This will fix the following error message:
Ocurrió un error ConexionPDOSQLSTATE=HY000, SQLDriverConnect: -11005 [Informix][Informix ODBC Driver]Unspecified System Error...
Related
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.
This is the common error often reported in questions:
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Please assume correctly that I've been reading posts for ... 'days'!
I've done all the following:
1) Uncommented: extension=php_pdo_odbc.dll in php.ini
2) Set-up a system DSN in SysWOW64\odbcad32.exe
3) Checked that odbcjt32.dll is present in SysWOW64
My standard (latest PHP) code:
if (!file_exists($dbName)) {die("Could not find database file.");}
try {
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=$dbq;Uid=$user;Pwd=$password");
}
catch (PDOException $e)
{
echo $e->getMessage();
}
There is no file_exists error (so addressing isn't the issue)
The .mdb is mine (so I know the correct Uid/Pwd)
The .mdb is in the same inetpub folder as the .php file calling it (so not permissions)
In windows powershell, I've run: Get-OdbcDsn which correctly shows the rich1 system DSN:
Name : rich1
DsnType : System
Platform : 32-bit
DriverName : Microsoft Access Driver (*.mdb)
Attribute : {DBQ, DriverId, ImplicitCommitSync, Threads...}
Still the same error :-( so I'm dead ended.
Does anyone know of any more 'Get-OdbcDsn' type routines that will help diagnose what's going on? Or any kind of new tack that leads me away from this dead end?
I am developing an application that needs to get data from an outside MSSQL database. I spent a lot of time trying to get various methods of connection to MSSQL with PHP, but there were several routes which were depreciated.
On my production environment running Debian, I was able to make a connection with PDO_DLIB and FreeTDS with something like this:
$this->db = new \PDO('dblib:host='.$thedb_host_prod.';dbname='.$thedb_database_name_prod, $thedb_database_user, $thedb_database_pass);
On Windows, MSSQL is depreciated. I believe I'm using the Microsoft SQL Server Driver and was only able to get it to work with ODBC, which looks something like this:
$dsn = "Driver={SQL Server};Server=".$thedb_host_dev.";Database=".$thedb_database_name_dev;
$this->odbc = odbc_connect($dsn, $thedb_database_user, $thedb_database_pass);
Then, the problem becomes, in each method I need to do something differently for ODBC than I do for DLIB.
public function exampleMethod(){
// logic and create the query in $query
if($this->dev == false){
// PRODUCTION
try {
$stmt = $this->db->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
} else {
// DEVELOPMENT
$query = $query;
$stmt = odbc_exec($this->odbc, ($query));
$result = array();
while($currentRow = odbc_fetch_object( $stmt )){
$jobNumber = $currentRow->Code; // Set object key to jobNumber
array_push($result, $currentRow);
}
}
}
This actually works, but the problem is, with how the query for ODBC needs to be prepared vs how the DBLIB query should be prepared, means that if I don't want to write the query twice in each method, I have to create it before each action. This is really bad because it means I'm not putting my variables into the query with PDO's bindValue.
So, has anyone been able to get PDO work with PHP 5.4 and MSSQL in a Windows environment? Does anyone see a way of securing the query in a way that doesn't make me duplicate the query in each method, once for ODBC and once for DBLIB?
My plan currently is to develop the application out and then remove all of the ODBC stuff which will allow me to put the query in the $stmt properly, avoiding this problem. But until then, it's making development a huge pain.
Oooook, so I finally got it working !
Here are the libraries / drivers for Sql-server connection via C/C++/java/PHP/etc.
Precisely, here are the Windows drivers for PHP.
Check out this page to know which version you need to get
They all exist in have 32 and x64, as well as "Thread safe" (ts) and "non-thread-safe" (nts) versions.
From what I read, nts versions are to be used if you work with IIS.
Usage :
Download and extract the package you need.
in my case, package 3.2, for php 5.6
Take necessary drivers
in my case, php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll
Put them in your php extensions directory
in my case, [...]\php5630vc11x86x170623162800\ext
If you wonder where this dir is inside your PHP, it should be quite easy to find, since you have plenty of other dlls here.
Likely, php_pdo_mysql.dll, php_pdo_pgsql.dll, etc.
Modify your php.ini
Be careful with Wamp, it seems to have one in the php directory AND another one in the apache dir.
Add lines to load the two extensions.
You can add them at the end of your file, or with the other extensions loading.
In my case, here's what I added :
;SQL-srever extensions
extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll
This part was for the PHP/PDO side.
For the driver to actualy work, you also need your (Windows) machine to have the ODBC drivers installed.
Feel free to try your connection already, but if it whines that you need the ODBC driver, go get it here :
Microsoft® ODBC Driver 11 for SQL Server®
And last, but not least, be sure to use the right format for your PDO connection.
$conn = new PDO ("sqlsrv:Server=$srv_host;database=$srv_dbname";
For comparison, here's what I wsa using on my linux server :
$conn = new PDO ("dblib:host=$srv_host:$srv_port;dbname=$srv_dbname", "$srv_username", "$srv_password");
I thought this syntax was common to all PDO drivers, but it appears I was wrong.
Here is the PHP PDO driver documentation.
I just actually had to do some work in php connecting to a MSSQL server. I did have to downgrade to php 5.4 due to the fact that the php_pdo_sqlsrv.dll is not updated for 5.5. For the dll files check here. But now down to the code I used to connect once you have the .dll files in the right place.
try {
$db = new PDO("sqlsrv:Server={$host};Database={$database}", $userName, $password);
}catch(PDOException $e){
die("failed to connect");
}
Just a standard PDO connection. Just in order to get it to work you must make sure that the .dll files are in the php directory.
I hope that answers at least part of the question.
I have worked with PHP 5.4 and SQL Server with PDO on Windows.
I strongly recommend using Microsoft's Web Platform Installer to set everything up. You can use it to install PHP, a local version of SQL Server Express to develop on, the official PHP driver for SQL Server, and IIS, all set up to work together.
One note of caution: The last release of the SQL Server PDO driver was in April, 2012. I reported a bug against it last year and was told that it's in "limited support", which apparently translates to "you're on your own". In any case, it worked reasonably well.
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.
I have a website that runs in Windows server, and it works perfectly fine. I tried to make a copy in my localhost but I get the error:
Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\xampp\htdocs\tdms\webfolders\secured\db_fns.php on line 29
Could not connect to database server
line 29 contains:
function fgsdb_connect()
{
$a=array();
$retvar=0;
$result = odbc_connect('FGS','tdms','tdms358',SQL_CUR_USE_ODBC); //---->line 29
if (!$result) // cannot establish connection to database
throw new Exception('Could not connect to database server');
else // connection to database has been established
return $result;
}
I am really new to odbc. the website is written in php and the database that i use in mySQL. though i figured that the database that it is trying to connect is a microsoft access MDE file. (i checked in the site in windows server.) What should i do? im sorry but i am really
It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.
Go to control panel -> administrative tools --> select data sources(ODBC) --> then right click on that file --> go to properties --> in the shortcut tab -> change the path from
%windir%\System32\odbcad32.exe
to
%windir%\SysWOW64\odbcad32.exe
and make your connection. the driver for MS Access will work fine now.
If it doesnt work, try to connect to the ODBC with a sentence like this:
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\YourFolder\YourFile.mdb",'Youruser', 'YourPassword');
The last 2 leave then just the the '' if you dont have any user or password
I was getting the same error on PHP 7.0.8 64bit while trying to connect to an Access .mdb.
I had to do two things:
Install the 64bit version of "Microsoft Access Database Engine 2010 Redistributable" (even with Access 2016 installed I was getting your error). You can download the driver from:
https://www.microsoft.com/en-us/download/details.aspx?id=13255
Then, if you go to the ODBC Data Source Administrator, you should notice the 64bit version.
Change the driver string to:
Driver={Microsoft Access Driver (*.mdb, *.accdb)}
Hope it helps other people.