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...
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().
Anybody know any php frameworks that supports full SQL server 2008 ??
I know Codeigniter supports mssql.
Not sure if you are looking for a framework specific connection to MS SQL server however PHP does have support for SQL server connections with mssql_connect();
mssql_connect()
As user644051 had already mentioned below - present driver to connect CI with MSSQL is SqlSrv.
I managed to connect CI with MS SQL 2008 and started to work with it.
BUT the way you have to twist your CI code to force database to cough up the results... is not worth the effort.
Bottom line: MSSQL driver is not optimized to work flowlessly with CI contrary to MYSQL which allows for easy and smooth work.
For example SqlSrv driver doesn't work for CI insert_batch().
Although I'd like to use flexibility that MSSQL server offers - at the moment we have to wait for a driver that will allow for such a luxury in CI.
So for the moment I discourage you to use CI with MSSQL.
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.
We have an application which uses WAMP server. Now, there is a new requirement from a customer who wants to use MS SQL Server instead of MySQL.
How easy is it to port to SQL Server from MySQL. Also it has to retain this configuration.
Apache->PHP->SQL Server on windows.
How can I connect from Apache to SQL Server. Hope PHP works well with SQL server.
Please advise.
Thanks,
Vish
You don't need to do anything special with Apache, you just need to use the correct interface in PHP. That is, the mssql stuff that Tobias linked to, or - perhaps better - PDO which can be configured to use either MySQL or MS SQL. PDO would probably be a lot easier going forward if you have to end up supporting both database engines.
In terms of differences between the MySQL and SQL Server, there are quite a lot unfortunately. Most annoying will be that the syntax for certain types of queries will be slightly different (and DDL - that is, creating tables, indexes and so on - is completely different!) Though they both support a big enough subset of standard SQL that you can usually find a way to do most everything that works in both of them. But don't expect to just connect to SQL Server and have all of your queries written for MySQL "just work" - unfortunately, they won't.
I guess in the end, the easiest thing to do is just to try it out. If it looks like it's going to be too much (for example, if you're using a lot of 'obscure' MySQL features), then you might have to rethink your options.
There are huge differences between MYSQL and MS even in basic queries.
So, all your database work should be rewritten.
The rest is not a big deal.
I'm guessing you mean MSSQL?
http://us2.php.net/mssql
mySQL... msSQL ... basically the same. You shouldn't have any problems if you don't use "fancy" queries - best would be just to try it out and see what happens.