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

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 / 33
October 20, 2003
  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

Executing Microsoft SQL Server Stored Procedure from PHP on Linux - Conclusion
(Page 9 of 9 )

In this article, we discuss how to make Apache, PHP and FreeTDS work together,  executing Microsoft SQL Server stored procedures from Red Hat Linux 9.0.  Due to a bug in the FreeTDS original source code, mssql_bind(), mssql_execute(), and mssql_init() do not work with the default installation.  We give out a workaround to modify the PHP source code so that these functions work successfully.

This is also tested for PHP 4.3.2 with Apache 2.0.46, and FreeTDS 0.61.2 on Red Hat 9.0.  I would suggest you to try this on Red Hat 8.0 and 7.3.  The following is the testing environment I used for this article:

The Machines for Red Hat 9.0 Are:
Dell Dimension 4500 (2.4 GHz P4, 1 GB RAM)  with Apache 2.0.47 + FreeTDS 0.61.2 + PHP 4.3.3 installed

IBM ThinkPad T30 Laptop (1.8 GHz P4, 512 MB RAM), with Apache 2.0.46 + FreeTDS 0.61.2 + PHP 4.3.2 installed

The Machine for Windows Apache Is:
Same laptop as above (dual boot) with Windows XP + Apache 2.0.46 (precompiled binary) + PHP 4.3.2 (precompiled binary)

The Machine for MS SQL Server 2000:
Compatible PIII 1 GHz, 512 MB RAM with Windows 2000 Server installed.

It is really worthy to be mention that you cannot compile Sybase or Sybase_CT module with Microsoft SQL Server Module together without modification.  If you decide to use Sybase or Sybase_CT module,  mssql_xxx functions are still functional except  these 4 functions: mssql_bind(), mssql_execute(), mssql_init() and mssql_free_statment(), because mssql_xxx functions are treated as aliases of corresponding Sybase_xxx.

A workaround to keep these 4 functions is to remove the mssql alias definition in Sybase and Sybase_CT module from the function_entry part in php_sybase_ct.c or php_sybase_db.c files.  Recompile PHP with sybase_ct and mssql options.

Iíve provided a real sample here (I have Sybase Adaptive Server Enterprise 12.5 developer edition and Oracle Enterprise Server 8.1.7 installed on Red Hat 9.0):

./configure --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --target=i686-redhat-linux-gnu --prefix=/usr/local/php2 --with-config-file-path=/usr/local/php2  --enable-force-cgi-redirect --disable-debug --enable-pic --disable-rpath --enable-inline-optimization  --with-db4 --with-dom=/usr --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-gdbm --with-gettext --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-png --with-ming --with-regex=system --with-xml --with-expat-dir=/usr --with-zlib --with-layout=GNU --enable-bcmath --enable-exif --enable-ftp --enable-magic-quotes --enable-safe-mode --enable-sockets --enable-sysvsem --enable-sysvshm --enable-discard-path --enable-track-vars --enable-trans-sid  --enable-wddx --with-oci8=/home/oracle/product/8.1.7 --enable-sigchild  --with-mssql=/usr/local/FreeTDS --with-sybase-ct=/opt/sybase-12.5/OCS-12_5 --with-pcre-regex --with-mysql=/usr/local/mysql --with-pgsql=/usr/local/pgsql --with-imap=shared --with-imap-ssl --with-kerberos=/usr/kerberos --enable-memory-limit --enable-bcmath --enable-shmop --enable-versioning --enable-calendar --enable-dbx --enable-dio --enable-mcal  --disable-cli --with-apxs2filter=/usr/local/Apache2/bin/apxs

Repeat the steps in this article to install PHP, and remember to restart Apache. You will see sybase_ct and mssql modules co-exist in PHP from the test.php page on Linux.

On Windows, after removing the mssql alias definition in Sybase_CT module, use Visual C++ 6.0 to recompile and make a new php_sybase_ct.dll (you must at least have the Sybase Open Client installed on your Windows machine to access the header files and library files). Then copy php_sybase_ct.dll to your php extensions directory, uncomment the following 2 lines in your php.ini file:


Restart and you will see sybase_ct and mssql modules co-existing in PHP from test.php on Windows.

In my next article, Executing Sybase SQL Server Stored Procedure from PHP,  I will discuss how to expand PHP Sybase DB and Sybase CT functions by yourself, adding the exact same functions like: sybase_bind(), sybase_execute(), sybase_init() and sybase_free_statment()  into the PHP Sybase and Sybase_CT modules.

Reference Sites, Books and Articles:

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- 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 

Developer Shed Affiliates


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