Solved

php mssql

Posted on 2013-01-04
8
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:Chris Sandrini
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 110

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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.

617 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