Solved

php mssql

Posted on 2013-01-04
8
307 Views
Last Modified: 2013-01-07
I have a connection to a ms sql server I would Like to have the same kinder setup that I use with mysql where I call the connection into a recordset and be able to access different columns using

$row_recordset1['column name ']

instead of a array
0
Comment
Question by:beridius
8 Comments
 
LVL 11

Expert Comment

by:un1x86
ID: 38743111
How do you connect to the mssql server? PDO?
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38743372
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38745448
What version of PHP do you have?  What OS/Webserver?  Which version of MS SQL server?  

Details are important here.  PHP 5.2 and below on Windows can use the php_mssql driver while PHP 5.3 and above can not.  PHP 5.3 and above must use sqlsrv driver for direct access.  With the correct SQL Native Client installed, you can also use ODBC to connect.  PDO driver is available in some variations also.

What code are you using right now?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:rinfo
ID: 38746421
use adodb.inc.php
http://adodb.sourceforge.net/
you will have similar function to mssql.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38746541
Not to put too fine a point on it, but...
access different columns using $row_recordset1['column name '] instead of a array
The notation you show here is PHP array notation.  You may be surprised how easy it can be to move from your familiar MySQL to MSSQL.  For the most part, I've found that you can replace mysql_query() with mssql_query() and use mssql_fetch_assoc() to retrieve the records from the result resource.  Some notable differences...

There is no analog to mysql_real_escape_string().  I made my own mssql_real_escape_string() function because the idea of using unescaped data made me itch.

The LIMIT clause is different.  In MySQL you might write SELECT thing FROM tbl LIMIT 3 but in MSSQL, you write SELECT TOP(3) thing FROM tbl.

There are other differences, but nothing that was difficult to overcome, and the online documentation you can find with a Google search was always enough to get me going.  But with that said, if I were trying to write a high-performance web service, I would not have tried to do this myself -- I would have hired the MSSQL 3-banana man!

HTH, ~Ray
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38747158
@beridius does not seem to be responding so we can't know what's going on with him.
0
 
LVL 2

Author Comment

by:beridius
ID: 38750157
sorry thanks for your post the connection to mssql is mssql_query with mssql_fetch_assoc($data))


I dont use PDO. the PHP version is 5.3.14

here is one of my connections
$data = mssql_query("
SELECT      sum(Transactions) + sum(Duplicates)
FROM [SQL01].[dbo].[KPIDay_T]
WHERE        (iDHClientID = 90) AND (UpdtdWhn BETWEEN CONVERT(DATETIME, '$date1', 102) AND CONVERT(DATETIME, '$date2', 102))");
$row = mssql_fetch_assoc($query);

Open in new window

0
 
LVL 2

Author Closing Comment

by:beridius
ID: 38750472
Thanks Ray I checked my Code and you was right I was using a array thanks so much
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question