cancel
Showing results for 
Search instead for 
Did you mean: 

Can't pass date parameter to CR from PHP5?

Former Member
0 Kudos

Post Author: halfer

CA Forum: Data Connectivity and SQL

FolksI am having real trouble passing a date parameter to the Crystal Reports 9 component from PHP5 on Windows. It should be easy, of course, but no:$rptParam = $rptParams->Item(2);$t = $rptParam->ValueType; // This comes out to 10, which is correct for a Crystal date type//None of these work//$rptParam->SetCurrentValue("25/04/2007");//$rptParam->SetCurrentValue("25-04-2007");//$rptParam->SetCurrentValue("25 April 2007");//$rptParam->SetCurrentValue("#25/04/2007#");//$rptParam->SetCurrentValue('20070425');//$rptParam->SetCurrentValue("25/04/2007 00:00");//$rptParam->SetCurrentValue("00:00 25/04/2007");//$rptParam->SetCurrentValue("00:00 25/04/2007");//$rptParam->SetCurrentValue("25/Apr/2007");//$rptParam->SetCurrentValue(date('c'));//$rptParam->SetCurrentValue(time());// These don't work either//$v = new Variant(time(), VT_DATE);$v = variant_date_from_timestamp(time());$rptParam->SetCurrentValue($v);Any thoughts as to what I might be doing wrong? It results on every occasion in these errors:PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown Description: Unknown' in C:\dev-misc\crystal.php:57Stack trace:#0 C:\dev-misc\crystal.php(57): variant->SetCurrentValue(Object(variant))#1 thrown in C:\dev-misc\crystal.php on line 57Fatal error: Uncaught exception 'com_exception' with message 'Source: UnknownDescription: Unknown' in C:\dev-misc\crystal.php:57Stack trace:#0 C:\dev-misc\crystal.php(57): variant->SetCurrentValue(Object(variant))#1 thrown in C:\dev-misc\crystal.php on line 57 Thanks.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Post Author: halfer

CA Forum: Data Connectivity and SQL

I have discovered from our Java team that this ought to be possible. They access Crystal via a DLL written in C++ passing all parameters as strings, the relevant snippet being this:

For each string parameter { PEParameterFieldInfo PARAM_PVI; PEValueInfo PARAM_VI; // ... PEGetNthParameterField(jobid, 0, &PARAM_PVI); PARAM_PVI.ValueType = PE_PF_STRING; strcpy(PARAM_PVI.Name, param.c_str()); strcpy(PARAM_PVI.CurrentValue, value.c_str()); PEConvertPFInfoToVInfo(PARAM_PVI.CurrentValue, PARAM_PVI.ValueType, &PARAM_VI); PEAddParameterCurrentValue(jobid, param.c_str(), "", &PARAM_VI);}I am no C++ expert, but it looks like PARAM_PVI and PARAM_VI are

structs, which I imagine I can't access in PHP. I think it is the

function PEConvertPFInfoToVInfo that converts the supplied string

parameter to the required date/int/etc type.Has anyone got any ideas

on how to do this in PHP? If there are any experts out there, please help: I have almost run out of ideas.

Former Member
0 Kudos

Post Author: halfer

CA Forum: Data Connectivity and SQL

I would much appreciate a reply on this. My above solution is not as good as a parameterised approach, and I can't imagine that it is difficult. However my various guesses, in the absence of documentation on the CR site, have come to naught. Thanks in advance to all respondents.

Former Member
0 Kudos

Post Author: halfer

CA Forum: Data Connectivity and SQL

Well, I tried most variants here://$date = mktime(0, 0, 0, 4, 25, 2007);//$v = variant_date_from_timestamp($date);//$rptParams->GetItemByName('Route_date')->AddCurrentValue($v, 10);//$rptParam->SetCurrentValue("25/04/2007");//$rptParam->SetCurrentValue("25-04-2007");//$rptParam->SetCurrentValue("04/25/2007");//$rptParam->SetCurrentValue("2007/25/04");//$rptParam->SetCurrentValue("25 April 2007");//$rptParam->SetCurrentValue("#25/04/2007#");//$rptParam->SetCurrentValue('20070425');//$rptParam->SetCurrentValue("25/04/2007 00:00");//$rptParam->SetCurrentValue("00:00 25/04/2007");//$rptParam->SetCurrentValue("00:00 25/04/2007");//$rptParam->SetCurrentValue("25/Apr/2007");//$rptParam->SetCurrentValue(date('c'));//$rptParam->SetCurrentValue(time());//$rptParam->ClearCurrentValueAndRange();//$pv = new COM("CrystalRuntime.ParameterValueInfo");//$pv->ParameterValues = "2/20/2007";None of these worked. In the end I found that I could do this:$cVal = "#22/04/2007#";$rptParam = $rptParams->Item(2);

$rpt->RecordSelectionFormula = str_replace($rptParam->Name, $cVal, $rpt->RecordSelectionFormula);It's not quite as elegant, but it's bulletproof enough and it works!