We help IT Professionals succeed at work.

MSSQL-specific cmds  vs ODBC

lennyh
lennyh asked
on
When using php w/ an mssql db, is it preferable to use the mssql-specific db cmds (i.e. mssql_connect() etc.)?

Is there any good reason why one would use the odbc oriented commands (i.e. odbc_connect()) in this case?

Are the odbc oriented commands primarily provided for those dbs that have no built in db-specific commands?  Or am I missing something here?

Also, a related question -- When trying to run w/ the mssql cmd set, I am always getting an error indicating "Call to undefined function: mssql_connect()"
(I've uncommented the "extension=php_mssql70.dll" in php.ini).  The equivalent odbc routine works fine.

My environment is Xitami/php4/MSDE

Thanks for any advice.
Comment
Watch Question

Commented:
>When using php w/ an mssql db, is it preferable to use the mssql-specific db
cmds (i.e. mssql_connect()
>etc.)?

Definitely, because using php's native MSSQL interface shows a significant
speed advantage when compared to both (either with php's own ODBC extension or
via COM (ADO)) ODBC variants.

A comparison (http://php.weblogs.com/php_asp_7_reasons) of MSSQL native, ODBC,
ODBC via ADO, and OLEDB shows that php's native MSSQL interface is not only
faster, but outspeeds ODBC by about factor 5 (at least for the mentioned
benchmark, your milage may vary).

>Is there any good reason why one would use the odbc oriented commands (i.e.
odbc_connect()) in this
>case?
Not in this case, however ODBC usually is used as generic database interface.
If you want to ensure that your project is (mostly) independant on the
underlying database infrastructure, you might want to choose ODBC. Just keep in
mind that you're sacrificing speed for compatibility.

A reason why you probably don't want to use ODBC is that some functions just
don't work as expected, for example (quoted from the php manual):
"Using odbc_num_rows() to determine the number of rows available after a SELECT
will return -1 with many drivers"
For your case, this will also happen with MSSQL.

>Are the odbc oriented commands primarily provided for those dbs that have no
built in db-specific commands?
ODBC is provided to ensure connectivity to most usual databases, and very
often, if the database itself doesn't support a connection via ODBC, third
party wrapper drivers exist.
Naturally ODBC can't provide all special functions which are featured in the
dominant (Oracle, MSSQL, PostgresSQL, MySQL etc.) databases.
Also keep in mind that it is impossible to create a database connection via
odbc_connect() and then trying to use a database-specific command like
mssql_get_last_message().

>Also, a related question -- When trying to run w/ the mssql cmd set, I am
always getting an error indicating
>"Call to undefined function: mssql_connect()"
>(I've uncommented the "extension=php_mssql70.dll" in php.ini).  The equivalent
odbc routine works fine.

Check in the configured extension directory (extension_dir = ...) if the
configured dll actually exists (in the current version of PHP, 4.0.6, the MSSQL
extension is called php_mssql.dll), maybe you upgraded to a newer version
without upgrading the ini file?

Author

Commented:
nmeat,

Thank you for your helpful response.

Following up on your last suggestion, I dl'ed the latest php and was finally able to have the system recognize my mssql php statements.  

On a related subject, it appears that I do not understand the param list for the mssql_result statement.  I'm puzzled by the second parameter (indicated as "int i" in the php docs).  I assume the first param is the result from the mssql_query and the third is the field specification, but what is the second param?

Thanks again for you help.

Lenny Harris

Author

Commented:
nmeat,I don't think I explained my question very clearly.  I wish to retrieve info from consecutive rows with mssql_fetch_array.  I had assumed that after issuing the fetch_array, I had to issue mssql_result to actually retrieve the data (maybe that's not so).  So I guess my real question is: What mssql cmd sequence do I use to retireve specific columns from consecutive rows?

Hope I made that clear.

TIA.

Lenny

Author

Commented:
nmeat,
I finally figured it out.  As you can tell, I was a bit confused.

Thanks for your help.

Lenny

Explore More ContentExplore courses, solutions, and other research materials related to this topic.