Solved

php mssql

Posted on 2013-01-04
8
296 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 82

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
 
LVL 9

Expert Comment

by:rinfo
ID: 38746421
use adodb.inc.php
http://adodb.sourceforge.net/
you will have similar function to mssql.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

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 82

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now