Академический Документы
Профессиональный Документы
Культура Документы
Contents
[hide]
1 Introduction
2 Installation overview
3 Microsoft Drivers for SQL Server for PHP
4.1 Troubleshooting
5 FreeTDS on Linux (on Ubuntu by compiling an mssql.so extension)
6 Using FreeTDS on Debian Lenny
7 See Also
Introduction
This short manual is suitable if you are trying to run Moodle using the SQL*Server (MSSQL)
RDBMS. Steps detailed below must be performed before installing Moodle itself.
Some of this may also apply if you wish to access an MSSQL server for external db
authentication/enrollment.
First of all, minimum required version of MSSQL has been stabilised to MSSQL 2005 (v.9),
although it might work with MSSQL 2000 (v.8) or newer. All the development process
has been performed using MSSQL 2005 and there could be some unknown problems with
previous releases.
While PHP comes with one, more or less, standard extension (mssql) that provides access to
MSSQL databases, early we found some hard limits on it. Basically such default extension
has some limits that prevent us to use it at all (you can find more info about these
problems here).
So, in order to allow PHP (i.e. Moodle) to access to MSSQL DBs properly we have to install
a mssql extension alternative to save us from the problems related above. See the
sections below for details about the various options.
Installation overview
1. Get MSSQL Server installed and running. (A free limited version, SQL Server Express
Edition is available for testing.)
Make sure that you choose mixed authentication (Windows and local accounts) to
keep things simpler later. You'll be asked to define the "sa" account password (it's the
default System Administrator account which has full access to all databases by
default).
2. Make sure MS SQL Server can accept incoming TCP/IP connections on port 1433 (the
standard one).
You might need to explicitly allow this in your Windows firewall (see the Control
Panel). You may also need to edit options in the :SQL Server Configuration
Manager -> Network Configuration -> Protocols -> TCP/IP enabled
3. Open the "SQL Server Management Studio" and create a new empty database. If
you are using the "sa" account then you don't need to do anything else here.
4. Configure these settings in your created (and still empty) database:
ANSI NULLS Enabled = true (ALTER DATABASE xxxx SET ANSI_NULLS ON)
(Moodle 2.x only) Row Versioning Enabled (ALTER DATABASE xxxx SET
READ_COMMITTED_SNAPSHOT ON)
5. Get PHP installed with a web server. Unless you want to do it under IIS or some
other way, the packages on the Moodle download page are a good solution.
6. Choose one of the following specific sections for your server to install
the mssql extension alternative installed and running properly on your PHP
box.
7. Set the following settings in your php.ini file
mssql.textlimit = 20971520
mssql.textsize = 20971520
8. With all this properly configured, you can continue with a standard Moodle
installation.
If your web server is on Windows, use php_dblib.dll. Despite the name, it's
FreeTDS compiled for Windows. (Go to this page for information onUsing
FreeTDS for Unix.)
Originally we were using the DLLs available at Frank Kromann's site, but they
are outdated (using old versions of FreeTDS) and that has causedsome
problems in the past.
So, right now, the recommended way to use FreeTDS under Windows is to
use PHP 5.2.x following the following instructions:
1. Download the appropriate copy of php_dblib.dll from the list below, and
save it into your /PHP/ext directory.
PHP version
PHP 5.2.x (vc6)
Thread Safe
FreeTDS version
Download URL
Yes
Download!
No
Download!
Yes
Download!
No
Download!
Thanks to Remote-Learner] (Moodle Partner) and specially to Bryan Williams, donating one
Visual C++ 6.0 Pro license to Moodle. Thanks to Trevor Johnson and his builds of the dblib
extensions. Thanks to Daniele, Doug, Luis, Sean and many others by their collaboration
in MDL-14725. Thanks to Frediano Ziglio and James K. Lowden from freetds.org by their
support. Thanks to Alastair Hole by providing the PHP 5.3 builds of the libraries. Thanks!
(alternatively here you can find some instructions to build those freetds
extensions under win32 yourself)
extension=php_dblib.dll
Make sure that any lines referring to the php_mssql.dll extension are
DISABLED (commented out).
4. When the PHP engine loads the FreeTDS extension it needs to be passed
certain infiormation in order to be able to connect to your Moodle database.
To retrieve this information FreeTDS looks for a file called freetds.conf in the
root folder of the server that PHP installed on (e.g. C:\).
[global]
host = xxx.xxx.xxx.xxx (host name or ip of the MSSQL server)
port = 1433
client charset = UTF-8
tds version = 8.0
text size = 20971520
[global]
host = xxx.xxx.xxx.xxx (host name or ip of the MSSQL server)
instance = xxx (instance name, e.g. INST2)
port = 1433
client charset = UTF-8
tds version = 8.0
text size = 20971520
Notes:
You can configure FreeTDS to look for the freetds.conf file in any directory
that you want - you don't have to use C:\. To do this create a SYSTEM
MSSQL is usually installed with port 1433 as the default. However, if the
port was changed on your server when you installed MSSQL then you
need to specify the correct port number.
$CFG->dbtype
= 'mssql';
$CFG->dbhost
= 'localhost';
// Required
// assuming MS SQL is on the
= 'moodle';
= 'yourusername';
= 'yourpassword';
$CFG->dbpersist =
$CFG->prefix
false;
= 'mdl_';
If you don't have a config.php file yet, it can be generated as normal from the
Moodle installer. Alternatively you can use the config-dist.php file that comes
with the Moodle package to create your own config.php file.
6. Restart or start your web server. If Moodle still cannot communicate with
the database server, please turn display_startup_errors to "On" in your
/PHP/php.ini file, then restart the web server and check for any errors that
may indicate incorrect DLL versions or missing dependencies. These error
reports, turned off by default in PHP, can be vital in locating a problem with
new extension installations.
7. Database conection test, try this PHP script, just put in a text file called
test.php change ('localhost', 'db_user', 'db_password') to suite your setup,
and load from local host (http://localhost/test.php)...
<?php
$link = mssql_connect('localhost', 'db_user', 'db_password');
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo'Successful connection';
mssql_close($link);
?>
Troubleshooting
If you encounter some problems you can try:
check that you have DotNet framework 1.1 installed (later version are
installed on Vista, but you could need this specific one)
enable TCP/IP for MSSQL: SQL Server 2005 Network Configuration ->
Protocols for MSSQLSERVER -> TCP/IP (Enable) -> Properties -> Ip
Addresses -> 127.0.0.1 (Active+Enable)
make sure the SQL Server Browser service is running SQL Server 2005
Network Configuration -> SQL Server Services
if you are using SQL Server 2005 and you have the error 4004: Unicode
data in a Unicode-only collation or ntext data cannot be sent to clients
using DB-Library (such as ISQL) or ODBC version 3.7 or earlier, try the
ODBTP method (next chapter). The SQL Server complaining that it
doesn't support pure Unicode via TDS or older versions of ODBC.
Microsoft has deprecated DB-Library a long ago, in favor of ODBC, OLE
DB, or SQL Native Client. Many new features of SQL 2005 aren't
accessible via DB-Library so if you need them, you could have to switch
away from tools based on TDS and DB-Library :(
/etc/init.d/apache2 restart
At the end of the process, if all goes fine, you will find in the mssql section of
phpinfo();
MSSQL Support
enabled
Library version
FreeTDS
See Also
FreeTDS for Windows is obsolete and too slow as of 2011. See: Hardware
and Performance Forum
Errors FAQ
Categories:
Installation
XMLDB
DB
SQL databases