Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Is there an elegant way to view sql statements written in PDO?

Here's my query:

$sql=$con->prepare("Select registrationeventid from tblregistrationeventtoscreening where screeningperiodid in (select screeningperiodid from tblscreeningsubperiod where screeningsubperiodid =:screeningsubperiodid)");
            $sql->bindValue(':screeningsubperiodid', $screeningsubperiodid, PDO::PARAM_INT);
            $sql->execute();      

I want to "echo" it so I can be certain I've written a good query. In the past, I would use "echo." How can I pull the same thing off in PDO?

Based on what I've seen thus far, you can't. But I'd like to think there's a ninja out there who's figured something out.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

Ray, after I read your feedback, I was able to find a function line that took debugDumpParams and printed it using the <pre> tags. I added a little something so I could better identify which function it belonged to. The end result looks like this:

public static function debug_sql($sql, $function_name) {
	ob_start();
	$sql->debugDumpParams();
	$r = ob_get_contents();
	ob_end_clean();
	echo '<pre><b>function name:'.$function_name.'</b><br><br>'.htmlspecialchars($r).'</pre>';
	}

Open in new window


I do something like this: $check_query=self::debug_sql($sql, "reggie_id");

..and it gives me this:

function name:reggie_id

SQL: [194] Select registrationeventid from tblregistrationeventtoscreening where screeningperiodid in (select screeningperiodid from tblscreeningsubperiod where screeningsubperiodid =:screeningsubperiodid)
Params:  1
Key: Name: [21] :screeningsubperiodid
paramno=0
name=[21] ":screeningsubperiodid"
is_param=1
param_type=1

Not sure what some of those parameters mean, though. I've got another question that deals with that and would appreciate your input:

https://www.experts-exchange.com/questions/29004689/What-do-the-parameters-in-the-PDO-function-debugDumpParams-mean.html 

Thanks!

Not bad.