The Problem
Since moving my web application from a Windows Server to a Linux Server, I have encountered all sorts of issues with my SQL Wrapper Class, I hope that this is the last one...
I had been using the SQLSRV PDO Driver for Windows, but am now using dblib which I think uses ODBC, it is all quite confusing...
On the previous server, I was able to retrieve OUTPUT parameters from stored procedures extremely easily using the PDO bindParam() method.
However, this method does not seem to return my output parameters any more... Has anyone else experienced it?
It is quite hard for me to show some test code as my Wrapper Class builds the queries and parameters dynamically, but I assume it is something like this:
$this->query->bindParam(':some_param','some_value',PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT,$value['length']);
A few things to note:
The Stored Procedures are on the same server, and have not changed, thus I know they are still returning the OUTPUT parameters in the same way.
The PHP PDO code has not changed, the only variable here is the PDO driver being used.
My Question(s)
Has anyone experienced this issue with PHP, MSSQL and PDO from a Linux Server?
Are there any other methods using PDO or not, to connect to an MSSQL Database from Linux?
I am currently using PHP 5.5.18, is there a later version that might fix this? If so, what version and is it stable on CentOS 6?
Related
Here is the question:
I have old foxpro database that are used by my co. ERP. And I need to make a web page using PHP to display some data.
But I am not sure what I should use. In a recent project I used PHP::PDO_ODBC functions.
But one of my co-worker uses PHP::ODBC(unified) functions in one of his project.
1-What is the differences between the two?
2-Is one of them more secure?
3-Just like the MySQL functions are deprecated, is either PDO_ODBC or ODBC(Unified) deprecated??
4-Will an old FoxPRO DB or even older DB type work on both?
Thanks for any help regarding this!
I can't answer all your questions but there are a few things I learned recently. I just had to use an MS Access database in a project which is what brought me on to PDO and ODBC. I originally used ODBC, but I think the PDO is more recently updated and offers better error reporting. I couldn't get ODBC to report any query errors other than that it had failed. In the end I had to go back to using ODBC because I couldn't find the equivalent of a lot of these functions listed here in PDO (I'd already started my project in ODBC). For basic operations querying the database I found no difference between the two.
You've probably already seen this but it looks like foxPRO works fine with PDO
as seen here
(actually the bottom of this page has a link to the ODBC driver for foxPRO
What is the preferred method of accessing a Microsoft SQL Server database with PHP 5.3+ on Linux?
Given the different extension options now available I'm unsure which method is preferred based on reliability and performance. Right now I am using the mssql extension with FreeTDS, but I'd like to know if this isn't the best way.
I've heard some recommend using php-odbc/EasySoft because the mssql extension has been abandoned - yet others have said going the ODBC route isn't worth the performance hit.
The response to this stackoverflow question seems to touch on what I'm asking, however it's Windows centric.
Thank you!
I've had good results using PHP's PDO (PHP Data Objects) library for this sort of thing. There's an excellent tutorial at http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/. Just make sure you use the following template to initialize your database connection:
$dbh = new PDO("dblib:host=$host;dbname=$dbname", $user, $pass);
I use FreeTDS. It's far from satisfactory. In fact, I found your question because I live in hope that there must be a better solution and I keep looking for one. Unfortunately, FreeTDS seems to be the best option at the moment, if you're developing in a Linux environment.
If you were on Windows, you could obviously use the Microsoft SQL Server drivers for PHP which would be better, but even then there are missing features, like support for PDO lastInsertId().
This has probably been asked before but I can't find it anywhere.
I have just found out that the mssql extension has been dumped from php (I know it was a while ago I'm a bit slow).
I have a legacy app that is using it and all the mssql_query etc functions. I'm wondering what the suggested route is?
PDO?
Microsofts Driver
Move to another DB?
I'm not entirely averse to moving to mysql since everytime I have to move boxes I have huge issues getting MSSQL to work correctly with php. Is old mysql extension still supported or do I need to move to PDO anyway?
Is there an easy way to move to PDO? Any suggestions welcome.
PDO is recommended anyway to abstract to DB connections, so if you go to MySQL I'd highly recommend using it. If you're on windows environments connecting to SQL server then the MS SQLSRV library is likely a good route to take. I have used the odbc_* functions when dealing MSSQL in the past with no problems, including calling stored procs as well as my own queries.
Another DB which didn't have OS lock in would be a good move too though. MySQL is ubiquitous, however don't rule out alternatives without doing some research first.
I'm getting a new project some time now and wanted to use PHP for this one, as I don't have the time to get started with MVC and absolutely hate C# for Webdev.
So I was thinking of going "back to my roots" and use PHP and PDO for that. Problem is, the Databases are all SQL Server 2003 and I don't quite know how well that is covered in PDO.
Does anybody have experience with this or should I go on getting ASP.NET-MVC into my head (Which I will do anyways, but this project needs fast deployment...)
The most common problem when using PHP and MSSQL is using an old (faulty) driver. Also, have a read of the comments on the PHP MSSQL manual page.
I don't know that PDO supports MS SQL, however I have successfully used the ADODB abstraction layer against both MS SQL 2000 and 2008 without issues. Your mileage may vary...
I've been using ADODB for PHP on several projects for quite some time, and I like it for the ease of use and the efficiency.
I've never been too curious about the way that lib accesses data because you know...it just worked :) But today I realized I'm still relying on the legacy MySQL4 ADODB drivers. I'm using MySQL 5.x, and it would probably be better if I started using a recent driver with ADODB.
But there are two drivers I could use :
adodb-mysqli.inc.php
adodb-pdo_mysql.inc.php
From what I read mysqli is pretty similar to the old mysql extension, optimized for MySQL5, while PDO is a layer between PHP and various DB systems (including MySQL of course).
Which one of these driver do you use ? Which one do you think I should use, and more importantly why should I prefer mysqli over PDO_mysql (or the opposite) ?
Answer : After a few days and some deep code reading, I ended up using the "adodb-mysqli.inc.php" driver. On a kinda-trafic-heavy site, I noticed the DB load went slightly down, and the network trafic between the web server and the db server went down by about 6.5%, which is good.
The PDO-mysql driver is probably pretty good too, but as said below, it doesn't make much sense to use ADODB over PDO. So mysqli it is.
All tests point towards PDO being the most efficient and the fastest driver. I do not know, however, if it makes sense to use PDO over AdoDB
I may be wrong but from what I remember of looking at the drivers, binding of variables in statements is emulated in the adodb mysqli driver despite the mysqli extension supporting binding. The pdo_mysql driver does however do the binding using the extension, so if you are using this you may get better performance.
Also might be worth adding that I think if you want to use the pdo drivers with adodb you have to use a different connection syntax and pass a DSN, there was an example in the docs. I struggled to get it to work for a bit because I didn't read this.