Preferred method of accessing MS SQL with PHP 5.3+ on Linux - php

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().

Related

Cassandra PHP interface with CQL available/planned?

I'm trying to plan a web application that should use a noSQL solution - Cassandra seems to be a good solution. I saw there are libraries for PHP to manipulate the database like phpCassa.
Also I saw the new version of Cassandra 0.8 is introducing a query language CQL.
Are there php interfaces that use the CQL? What is the benefit using the CQL? Is it just a more sql-like way to make queries?
Thank you!
The link Greg posted above is to date the working repo and state of the php-cql driver efforts.
While a driver is not yet available it does not stop you from using CQL, the drivers are all going to be a wrapper of the thrift method "execute_cql_query" (Until a new transport is created anyway).
That means you can simply compile thrift for php or get it from an updated project and then pass your cql query to that method. It does mean manual handling of things that a driver will/should take care of.
"Is it just a more sql-like way to make queries?", basically...yes. One of the things that came up on the Cassandra mailing list was getting CQL to be as SQL-Like as possible.
"What is the benefit using the CQL?" Well, mainly that some new Cassandra users find the thrift API tedious to get to grips with, CQL may be much easier to learn since its is so close to the "normal" sql.
https://github.com/nicktelford/php-cql
I also believe that phpCassa should support it as well.
It's designed to make NoSQL more logical for people coming from SQL as a database engine.
This will really be helpful if you wish to use CQL to communicate with Cassandra via PHP
https://gist.github.com/1024060/983a5607390433b77d5c2e64a4ee148f4df46b69
This is a sample of what zcourts mentioned in his previous post
Regards,
Tamil
The official CQL drivers supported by the Apache Cassandra project at large are, I believe, all on Apache Extras, at this link:
http://code.google.com/a/apache-extras.org/hosting/search?q=label:cql
The PHP one is at
http://code.google.com/a/apache-extras.org/p/cassandra-pdo/
Connection via Thrift deprecated.
I am using PHP library for Cassandra database via a binary protocol.

What is the suggested migration route from mssql extension in php

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.

Oracle, PDO_OCI vs OCI8

The company I work for currently uses some basic functions to abstract the OCI libraries as a means for DB connectivity. We're considering switching to PHP's PDO object, but from some quick searches, it looks like the Oracle driver is a bit less mature than the other PDO drivers. I would appreciate some pro/cons for PDO/oci8 from anyone who has used it in a production environment.
Thanks!
I don't have personal experience with the PDO driver (being tagged as experimental was enough for not even considering it). But in The Underground PHP and Oracle Manual we can read the following, as preface to the PHP PDO Extension chapter:
The PDO extension and PDO_OCI driver are open source and included in
PHP 5.1 onwards. Oracle does not contribute to PDO_OCI.
The PHP community has let the PDO project languish and Oracle recommends using
OCI8 instead whenever possible because of its better feature set,
performance, reliability and stability. Use of PDO_OCI for general
purpose applications is not recommended.
The extension is not finished, it's probably poorly maintained (although some bug fixes get through now and then) and it's been that way for years. I would not put my eggs in that basket.
It seems to me that Oracle is not interested in developing a driver for PDO it's developing it's own driver to keep you close to oracle database... to oracle driver... etc. :)
As far as I've seen there is no problem if you can cope with max. texts of VARCHAR2 of 4000 CHARS. If you need CLOBs (and/or bigger) don't go with PDO_OCI.
I've created a suite of classes "PDOSurrogate" as a drop in replacement for PDO with Oracle.
When PDO is mature enough I can use Refactor->Rename to change it to PDO.
May be I'm too late to the party .. just thought to add some value to the discussion. I am experienced in OCI8 and OCI8_11 extension and have done some extensive workload using stored procedures/packages, CLOB/BLOB's and XML I never had to run out of options .. further it seems very reliable and can handle extensive loads and I have even used once for an ETL(Extract Transform Load) applications to handle heavy workloads... also believe oci8 is the widely used extension .. than pdo ..

How well is SQL Server implemented in PDO?

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...

What's the most efficient driver to use with ADODB to access a MySQL5 Database?

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.

Categories