Home arrow PHP arrow Page 6 - Executing Microsoft SQL Server Stored Procedure from PHP on Linux
PHP

Executing Microsoft SQL Server Stored Procedure from PHP on Linux


Learn how to setup, install and configure Apache and PHP on a Linux box to execute MS SQL stored procedures. This extensive article takes you through an in-depth look on how to achieve your ideal environment.

Author Info:
By: Jack Zhang
Rating: 4 stars4 stars4 stars4 stars4 stars / 32
October 20, 2003
TABLE OF CONTENTS:
  1. · Executing Microsoft SQL Server Stored Procedure from PHP on Linux
  2. · Preparation
  3. · Installing the Apache Web Server
  4. · Installing the Apache Web Server, Cont'd
  5. · Installing FreeTDS
  6. · Modify the PHP Source Code
  7. · Modify the PHP Source Code, Cont'd
  8. · Executing MS SQL Server Procedures from PHP
  9. · Conclusion

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials