The dll that is included in PHP4Delphi 6.2 is not compatible with PHP 5.2.2, but source code is compatible.
Just today I compiled this demo for PHP 5.2.2 and it works fine for me.
If you a problem with it, can you specify it more precisely, please?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
function minit(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
RESULT := SUCCESS;
end;
function mshutdown(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
RESULT := SUCCESS;
end;
function GetReportS(grf, datacon, SQL: string): ansistring;
var
TempGridppReport: TGridppReport;
f1, f2, scon: string;
f: TextFile;
TS: TStringList;
begin
f1 := 'c:\g.tmp';
f2 := 'c:\lg.tmp';
// When I delete The all code in function GetReports ,it will work
// But the code works well with PHP5.1.x {.$DEFINE PHP520}
TempGridppReport := TGridppReport.Create(nil);
TempGridppReport.LoadFromFile(grf);
TempGridppReport.DetailGrid.Recordset.ConnectionString := datacon;
TempGridppReport.DetailGrid.Recordset.QuerySQL := SQL;
TempGridppReport.GenerateDocumentFile(f1);
Base64Encode(f1, f2);
TS := TStringList.Create;
try
AssignFile(f, f2);
Reset(f);
while not Eof(f) do
begin
Readln(f, scon);
TS.Add(scon);
end;
CloseFile(f);
finally
Result := ts.Text;
ts.Free;
TempGridppReport.Free();
if FileExists(f1) then
DeleteFile(f1);
if FileExists(f2) then
deletefile(f2);
end;
end;
//function GetReportS(grf,datacon,SQL: string): string;
//only for PHP5.2x
procedure php_GetReportS(ht: integer; return_value: pzval; return_value_ptr: ppzval; this_ptr: pzval;
return_value_used: integer; TSRMLS_DC: pointer); cdecl;
var
param: pzval_array;
grf, datacon, sql, st: string;
begin
if (not (zend_get_parameters_ex(ht, Param) = SUCCESS)) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
grf := param[0]^.value.str.val;
datacon := param[1]^.value.str.val;
sql := param[2]^.value.str.val;
st := GetReportS(grf, datacon, SQL);
ZVAL_STRING(return_value, PChar(st), true);
dispose_pzval_array(param);
end;
var
moduleEntry: Tzend_module_entry;
module_entry_table: array[0..0] of zend_function_entry;
function get_module: Pzend_module_entry; cdecl;
begin
if not PHPLoaded then
LoadPHP;
ModuleEntry.size := sizeof(Tzend_module_entry);
ModuleEntry.zend_api := ZEND_MODULE_API_NO;
ModuleEntry.zts := USING_ZTS;
ModuleEntry.Name := 'php_Grid++report';
ModuleEntry.version := '1.0';
ModuleEntry.module_startup_func := @minit;
ModuleEntry.module_shutdown_func := @mshutdown;
ModuleEntry.request_startup_func := @rinit;
ModuleEntry.request_shutdown_func := @rshutdown;
ModuleEntry.info_func := @php_info_module;
if (extension_loaded($module)) {
$str = "module loaded";
} else {
$str = "Module $module is not compiled into PHP";
}
echo "$str\n";
$functions = get_extension_funcs($module);
echo "Functions available in the $module extension:<br>\n";
foreach($functions as $func) {
echo $func."<br>\n";
}
echo GetReportS("test", "test", "test");
?>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem is the function GetReportS works very well with 5.1.4 with "{$DEFINE PHP512}"
In PHP 5.2.2 ( recomplined with "{$DEFINE PHP520}" ),it can be loaded correctly,but when I call it ,something error comes.
The same code ,works with 5.1.x ( $DEFINE PHP512} ) ,but not works with 5.2.X ("{$DEFINE PHP520}").
I'm sorry for my poor english,and so sorry for wasting your time!
function GetReportS(grf, datacon, SQL: string): ansistring;
var
TempGridppReport: TGridppReport;
f1, f2, scon: string;
f: TextFile;
TS: TStringList;
begin
f1 := 'c:\g.tmp';
f2 := 'c:\lg.tmp';
// When I delete The all code in function GetReports ,it will work
// But the code works well with PHP5.1.x {.$DEFINE PHP520}
TempGridppReport := TGridppReport.Create(nil);
TempGridppReport.LoadFromFile(grf);
TempGridppReport.DetailGrid.Recordset.ConnectionString := datacon;
TempGridppReport.DetailGrid.Recordset.QuerySQL := SQL;
TempGridppReport.GenerateDocumentFile(f1);
Base64Encode(f1, f2);
TS := TStringList.Create;
try
AssignFile(f, f2);
Reset(f);
while not Eof(f) do
begin
Readln(f, scon);
TS.Add(scon);
end;
CloseFile(f);
finally
Result := ts.Text;
ts.Free;
TempGridppReport.Free();
if FileExists(f1) then
DeleteFile(f1);
if FileExists(f2) then
deletefile(f2);
end;
end;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you check my previous answer, you will see the modifications I made to your sources in order to make more correct PHP extension. I would recommend you to apply it for your project.
Concerning the last problem with your function I found the following:
If you add AxtiveX unit to your uses section and modify GetReportS by adding CoInitialize and CoUninitialize it works.
procedure php_GetReportS(ht: integer; return_value: pzval; return_value_ptr: ppzval; this_ptr: pzval;
return_value_used: integer; TSRMLS_DC: pointer); cdecl;
var
param: pzval_array;
grf, datacon, sql, st: string;
begin
if (not (zend_get_parameters_ex(ht, Param) = SUCCESS)) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
CoInitialize(nil);
grf := param[0]^.value.str.val;
datacon := param[1]^.value.str.val;
sql := param[2]^.value.str.val;
st := GetReportS(grf, datacon, SQL);
ZVAL_STRING(return_value, PChar(st), true);
dispose_pzval_array(param);
CoUninitialize;
end;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Demo "phpRegistry" does not work with PHP 5.2.2
PHP4Delphi version is 6.2.2
The dll that is included in PHP4Delphi 6.2 is not compatible with PHP 5.2.2, but source code is compatible.
Just today I compiled this demo for PHP 5.2.2 and it works fine for me.
If you a problem with it, can you specify it more precisely, please?
The Code works well with PHP5.1.4,But not work with PHP5.2.2(recompiled with
{$DEFINE PHP520} )
Thank you!
The report http://www.rubylong.cn/Download/Grid++Report4.0cn.zip
library php_Greport;
{$I PHP.INC}
uses
Windows, Classes, SysUtils, math, ZendTypes, ZENDAPI, PHPTypes, PHPAPI, DB, ADODB, OleServer, grproLib_TLB, OleCtrls, base64;
function rinit(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
Result := SUCCESS;
end;
function rshutdown(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
Result := SUCCESS;
end;
procedure php_info_module(zend_module: Pzend_module_entry; TSRMLS_DC: pointer); cdecl;
begin
php_info_print_table_start();
php_info_print_table_row(2, PChar('Lg Grid++ Report Module for PHP 5.2x'), PChar('Enabled'));
php_info_print_table_row(2, PChar('Email'), PChar('Li_mi@yeah.net'));
php_info_print_table_end();
end;
function minit(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
RESULT := SUCCESS;
end;
function mshutdown(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
RESULT := SUCCESS;
end;
function GetReportS(grf, datacon, SQL: string): ansistring;
var
TempGridppReport: TGridppReport;
f1, f2, scon: string;
f: TextFile;
TS: TStringList;
begin
f1 := 'c:\g.tmp';
f2 := 'c:\lg.tmp';
// When I delete The all code in function GetReports ,it will work
// But the code works well with PHP5.1.x {.$DEFINE PHP520}
TempGridppReport := TGridppReport.Create(nil);
TempGridppReport.LoadFromFile(grf);
TempGridppReport.DetailGrid.Recordset.ConnectionString := datacon;
TempGridppReport.DetailGrid.Recordset.QuerySQL := SQL;
TempGridppReport.GenerateDocumentFile(f1);
Base64Encode(f1, f2);
TS := TStringList.Create;
try
AssignFile(f, f2);
Reset(f);
while not Eof(f) do
begin
Readln(f, scon);
TS.Add(scon);
end;
CloseFile(f);
finally
Result := ts.Text;
ts.Free;
TempGridppReport.Free();
if FileExists(f1) then
DeleteFile(f1);
if FileExists(f2) then
deletefile(f2);
end;
end;
//function GetReportS(grf,datacon,SQL: string): string;
//only for PHP5.2x
procedure php_GetReportS(ht: integer; return_value: pzval; return_value_ptr: ppzval; this_ptr: pzval;
return_value_used: integer; TSRMLS_DC: pointer); cdecl;
var
param: pzval_array;
grf, datacon, sql, st: string;
begin
if (not (zend_get_parameters_ex(ht, Param) = SUCCESS)) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
grf := param[0]^.value.str.val;
datacon := param[1]^.value.str.val;
sql := param[2]^.value.str.val;
st := GetReportS(grf, datacon, SQL);
ZVAL_STRING(return_value, PChar(st), true);
dispose_pzval_array(param);
end;
var
moduleEntry: Tzend_module_entry;
module_entry_table: array[0..0] of zend_function_entry;
function get_module: Pzend_module_entry; cdecl;
begin
if not PHPLoaded then
LoadPHP;
ModuleEntry.size := sizeof(Tzend_module_entry);
ModuleEntry.zend_api := ZEND_MODULE_API_NO;
ModuleEntry.zts := USING_ZTS;
ModuleEntry.Name := 'php_Grid++report';
ModuleEntry.version := '1.0';
ModuleEntry.module_startup_func := @minit;
ModuleEntry.module_shutdown_func := @mshutdown;
ModuleEntry.request_startup_func := @rinit;
ModuleEntry.request_shutdown_func := @rshutdown;
ModuleEntry.info_func := @php_info_module;
module_entry_table[0].fname := 'GetReportS';
module_entry_table[0].handler := @php_GetReportS;
ModuleEntry.functions := @module_entry_table[0];
ModuleEntry._type := MODULE_PERSISTENT;
result := @ModuleEntry;
end;
exports
get_module;
end.
I have upload the file
http://www.bestsharing.com/files/cxTprL283189/phpreport52_.rar.html
the password is :
Grid++Report4.0cn.zip
Thank you!
here is a working version of your extension. To make it more simple I removed some code from function GetReportS.
library php_Greport;
{$I PHP.INC}
uses
Windows, Classes, SysUtils, math, ZendTypes, ZENDAPI, PHPTypes, PHPAPI;
function rinit(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
Result := SUCCESS;
end;
function rshutdown(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
Result := SUCCESS;
end;
procedure php_info_module(zend_module: Pzend_module_entry; TSRMLS_DC: pointer); cdecl;
begin
php_info_print_table_start();
php_info_print_table_row(2, PChar('Lg Grid++ Report Module for PHP 5.2x'), PChar('Enabled'));
php_info_print_table_row(2, PChar('Email'), PChar('Li_mi@yeah.net'));
php_info_print_table_end();
end;
function minit(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
RESULT := SUCCESS;
end;
function mshutdown(_type: integer; module_number: integer; TSRMLS_DC: pointer): integer; cdecl;
begin
RESULT := SUCCESS;
end;
function GetReportS(grf, datacon, SQL: string): ansistring;
begin
Result := 'test string to check return value';
end;
//function GetReportS(grf,datacon,SQL: string): string;
//only for PHP5.2x
procedure php_GetReportS(ht: integer; return_value: pzval; return_value_ptr: ppzval; this_ptr: pzval;
return_value_used: integer; TSRMLS_DC: pointer); cdecl;
var
param: pzval_array;
grf, datacon, sql, st: string;
begin
if (not (zend_get_parameters_ex(ht, Param) = SUCCESS)) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
grf := param[0]^.value.str.val;
datacon := param[1]^.value.str.val;
sql := param[2]^.value.str.val;
st := GetReportS(grf, datacon, SQL);
ZVAL_STRING(return_value, PChar(st), true);
dispose_pzval_array(param);
end;
var
moduleEntry: Tzend_module_entry;
module_entry_table: array[0..1] of zend_function_entry;
function get_module: Pzend_module_entry; cdecl;
begin
if not PHPLoaded then
LoadPHP;
ModuleEntry.size := sizeof(Tzend_module_entry);
ModuleEntry.zend_api := ZEND_MODULE_API_NO;
ModuleEntry.zts := USING_ZTS;
ModuleEntry.Name := 'php_greport';
ModuleEntry.version := '1.0';
ModuleEntry.module_startup_func := @minit;
ModuleEntry.module_shutdown_func := @mshutdown;
ModuleEntry.request_startup_func := @rinit;
ModuleEntry.request_shutdown_func := @rshutdown;
ModuleEntry.info_func := @php_info_module;
module_entry_table[0].fname := 'GetReportS';
module_entry_table[0].handler := @php_GetReportS;
module_entry_table[1].fname := nil;
module_entry_table[1].handler := nil;
ModuleEntry.functions := @module_entry_table[0];
ModuleEntry._type := MODULE_PERSISTENT;
result := @ModuleEntry;
end;
exports
get_module;
end.
test script:
<?
if(!extension_loaded('php_greport')) {
dl('php_greport.dll');
}
$module = 'php_greport';
if (extension_loaded($module)) {
$str = "module loaded";
} else {
$str = "Module $module is not compiled into PHP";
}
echo "$str\n";
$functions = get_extension_funcs($module);
echo "Functions available in the $module extension:<br>\n";
foreach($functions as $func) {
echo $func."<br>\n";
}
echo GetReportS("test", "test", "test");
?>
Yes,I know the simple GetReportS works.
The problem is the function GetReportS works very well with 5.1.4 with "{$DEFINE PHP512}"
In PHP 5.2.2 ( recomplined with "{$DEFINE PHP520}" ),it can be loaded correctly,but when I call it ,something error comes.
The same code ,works with 5.1.x ( $DEFINE PHP512} ) ,but not works with 5.2.X ("{$DEFINE PHP520}").
I'm sorry for my poor english,and so sorry for wasting your time!
function GetReportS(grf, datacon, SQL: string): ansistring;
var
TempGridppReport: TGridppReport;
f1, f2, scon: string;
f: TextFile;
TS: TStringList;
begin
f1 := 'c:\g.tmp';
f2 := 'c:\lg.tmp';
// When I delete The all code in function GetReports ,it will work
// But the code works well with PHP5.1.x {.$DEFINE PHP520}
TempGridppReport := TGridppReport.Create(nil);
TempGridppReport.LoadFromFile(grf);
TempGridppReport.DetailGrid.Recordset.ConnectionString := datacon;
TempGridppReport.DetailGrid.Recordset.QuerySQL := SQL;
TempGridppReport.GenerateDocumentFile(f1);
Base64Encode(f1, f2);
TS := TStringList.Create;
try
AssignFile(f, f2);
Reset(f);
while not Eof(f) do
begin
Readln(f, scon);
TS.Add(scon);
end;
CloseFile(f);
finally
Result := ts.Text;
ts.Free;
TempGridppReport.Free();
if FileExists(f1) then
DeleteFile(f1);
if FileExists(f2) then
deletefile(f2);
end;
end;
If you check my previous answer, you will see the modifications I made to your sources in order to make more correct PHP extension. I would recommend you to apply it for your project.
Concerning the last problem with your function I found the following:
If you add AxtiveX unit to your uses section and modify GetReportS by adding CoInitialize and CoUninitialize it works.
procedure php_GetReportS(ht: integer; return_value: pzval; return_value_ptr: ppzval; this_ptr: pzval;
return_value_used: integer; TSRMLS_DC: pointer); cdecl;
var
param: pzval_array;
grf, datacon, sql, st: string;
begin
if (not (zend_get_parameters_ex(ht, Param) = SUCCESS)) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
CoInitialize(nil);
grf := param[0]^.value.str.val;
datacon := param[1]^.value.str.val;
sql := param[2]^.value.str.val;
st := GetReportS(grf, datacon, SQL);
ZVAL_STRING(return_value, PChar(st), true);
dispose_pzval_array(param);
CoUninitialize;
end;
Thanks a lot