Solved

php mssql

Posted on 2013-01-04
8
310 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: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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

710 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