Why does this not work?

Posted on 2016-07-28
Last Modified: 2016-08-02
Here's the function the way I run it in MSSQL Studio...

select dbo.ufn_ClientPreference( 28  , 'StatementRollUp' )

Here's the way I run it using PDO:

function test(){
global $mssql_pdo;	'

$sql="select dbo.ufn_ClientPreference( 28 , 'StatementRollUp' ) as StatementRollUp";

		echo "nope";


//echo "yes";

		<td><?php echo $row['StatementRollUp'];?></td>

Open in new window

No specific errors, just a page that says it can't be displayed.

What's wrong?
Question by:brucegust
  • 3
  • 3
LVL 108

Expert Comment

by:Ray Paseur
ID: 41733039
Stray apostrophe on line 4, maybe?  Looks like a PHP parse error to me.
LVL 108

Accepted Solution

Ray Paseur earned 500 total points
ID: 41733050
Also, it might be a good idea to write the function like this (fragment) that uses dependency injection instead of globals.
function test($mssql_pdo){
    $sql = "select dbo.ufn_ClientPreference( 28 , 'StatementRollUp' ) as StatementRollUp";
    $query = $mssql_pdo->query($sql);

Open in new window

Here's an explanation of why:

Author Comment

ID: 41733070
Nuts! Ray, that was a typo. There is no stray apostrophe, I just slipped when I was copying the code.

Here's the thing: There was another scenario in my last job where, in the context of PDO, if you were interacting with a T-SQL Stored Procedure, you couldn't create a temp table within the procedure. I don't have my notes in front of me, so I'm just trying to remember. But the bottom line was that there appeared to be certain situations where if you were using PDO and calling any T-SQL functions and / or stored procedures, you needed to proceed with caution because within that dynamic you had a breakdown in communication. Does that resonate with you? Have you encountered that situation where you were using PDO to interact with a T-SQL database in a way that incorporated Stored Procedures and / or functions on the server and found that what may run without any problem in MSSQL Studio did not translate in PDO?
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.


Author Comment

ID: 41738871
Ray, I'm going to close the question. As always, I appreciate your time. The app I'm working on is using "pconnect." How that differs from a PDO connection and whether or not that would / could make any difference in the way a stored procedure or a function on the server would fire, I don't know. I'm thinking there are other variables at work here that I'm not necessarily aware of and I was able to solve the problem that I was working on, so this is a moot point...for now, anyway.

Thanks again!
LVL 108

Expert Comment

by:Ray Paseur
ID: 41739014
Here's pconnect() - generic, but still well-explained.

Here's connect() - not persistent.

Why prefer connect() over pconnect()?  If you're using pconnect() and anything goes wrong in another script using the connection that causes any kind of damage to the connection, you may experience intermittent run-time failures that cannot be replicated.  Professionals do not like to debug those sorts of things; we prefer ways of working that are stable and predictable, with a minimum of "spooky action at a distance."  If you still think there is an advantage to pconnect() consider attaching a script timer to the processes and see if pconnect() saves you any noticeable amount of script time.

Author Comment

ID: 41739203
I'm getting to a place where I think some programmers simply default to what they're most familiar with rather than venturing beyond the reservation and use something else that may be more efficient.

In this instance, based on the explanations you've referred as well as some other things I've read, it looks as though pconnect may be the better option, but I'm still suspicious that while PHP and T-SQL can get along, there are some anomalies that represent some "quirks," so even when the PHP code is sound, you don't always get the recordset you expect. Not a dealbreaker necessarily, but something to be sensitive when attempting to troubleshoot some code.


Featured Post

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

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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.  …
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 …

744 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

15 Experts available now in Live!

Get 1:1 Help Now