Executing Microsoft SQL Server Stored Procedure from PHP on Linux - Modify the PHP Source Code
(Page 6 of 9 )
We have now come to the critical part in this article. Change directory to php-4.3.3, and issue the following command:
cd /public/php-4.3.3
We need to modify some source code before we proceed to compile and install PHP. The reason to do this is: mssql_bind(), mssql_execute(), and mssql_init() do not work with FreeTDS without modification. I have compiled the PHP mssql module source code under the Windows system (Windows 2000/XP). Using Microsoft Visual C++ 6.0 by linking to the MS SQL Server DB library NTWDBLIB.LIB, these 3 functions works just fine under Windows (real functions that connect to MS SQL Server are in NTWDBLIB.DLL, which is installed with Windows and resides in SYSTEM32 folder).
On Linux, when we use FreeTDS, libsybdb.so is equivalent to NTWDBLIB.DLL on Windows, and libsybdb.la is equivalent to NTWDBLIB.LIB.
I seem to have encountered a small bug in FreeTDS to emulate same RPC API functions as in NTWDBLIB.DLL (these functions are: dbrpcparam, dbrpcexec, dbsqlok; the buggy one here is dbrpcparam in FreeTDS).
From the php-4.3.3 folder, we go further down into the folder: ext/mssql, which holds PHP’s mssql module files. Issue the following:
cd ext/mssql
Or you can use:
cd /public/php-4.3.3/ext/mssql
from any directory on the filesystem.
Open the file php_mssql.c in gedit:
gedit php_mssql.c
Go to line# 1987, comment this line, as follows:
/* datalen=Z_STRLEN_PP(var); */
Add these lines of code:
if ((maxlen >0 ) && (maxlen <256))
datalen=maxlen;
else
{
maxlen =255;
datalen=255;
}
Go to line# 1996, (original line number before adding above code), comment this line, as follows:
/* datalen = -1; */
Add this line:
datalen = tds_get_size_by_type(type);
This is the section after the modifications:
if ( (type==SQLVARCHAR) || (type==SQLCHAR) || (type==SQLTEXT) ) { /* variable-length type */
if (is_null) {
maxlen=0;
datalen=0;
}
else {
convert_to_string_ex(var);
/*datalen=Z_STRLEN_PP(var); */
if ((maxlen >0 ) && (maxlen <256))
datalen=maxlen;
else
{
maxlen =255;
datalen=255;
}
value=(LPBYTE)Z_STRVAL_PP(var);
}
}
else { /* fixed-length type */
if (is_null) {
datalen=0;
}
else {
/*datalen=-1; */
datalen = tds_get_size_by_type(type);
}
maxlen=-1;
Save the file. Now we can configure the module tree, compile and install PHP.
Next: Modify the PHP Source Code, Cont'd >>
More PHP Articles
More By Jack Zhang