The problem of using FreeTDS to connect MSSQL Chinese garbled in Linux "reference 1"

Source: Internet
Author: User
Tags locale microsoft sql server 2005 mssql sybase

Because of the work we need to access our previous SQL Server 2005 data through PHP, so we have the birth of this article. Nonsense is less, do programming the least like to beat around the bush. Use the introduction steps to explain the problem and look down.
System: Linux
Database: SQL Server 2005 1. Download FreeTDS
Official website: http://www.freetds.org

2. Installing FreeTDS
# tar ZXVF freetds-current.tgz (unzip)
#./configure--prefix=/usr/local/freetds--with-tdsver=7.2--enable-msdblib
# make
# make install other optional depending on your situation
--enable-dbmfix--with-gnu-ld--enable-shared--enable-static install FreeTDS to directory/usr/local/freetds:--prefix=/usr/local/ FreeTDS If this is not the default, it seems that this directory corresponds to the database version--mine is Microsoft SQL Server 2005 so I'm taking--with-tdsver=7.2.
4.2 Sybase SQL Server < Microsoft SQL Server 6.5
5.0 Sybase SQL Server >= 10
7.0 Microsoft SQL Server 7.0
7.1 Microsoft SQL Server 2000
7.2 Microsoft SQL Server 2005 3. Edit/usr/local/freetds/etc/freetds.conf# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 Jklo Wden EXP $
#
# This file was installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# See the freetds.conf manpage ' man freetds.conf '. # Global settings is overridden by those in a database
# Server Specific section
[Global]
# TDS Protocol version
; TDS Version = 4.2 # Whether to write a tdsdump file for diagnostic purposes
# (Setting this to/tmp was insecure on a multi-user system)
; dump file =/tmp/freetds.log
; Debug flags = 0xffff # Command and connection Timeouts
; Timeout = 10
; Connect Timeout = Ten # If you get out-of-memory errors, it could mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try Setting ' text Size ' to a more reasonable limit
Text size = 64512 #解决中文乱码问题
Client Charset=utf8
# A Typical Sybase server
#[egserver50]
# host = symachine.domain.com
# port = 5000
# TDS Version = 5.0# A typical Microsoft server
#[egserver70]
# host = ntmachine.domain.com
# port = 1433
# TDS Version = 7.0# The name of the program and command line to use, what to call their own
[Server2005]
Host = 192.168.3.100 #我的SQL Server2005 IP, according to its own change
Port = 1433
TDS Version = 7.2
4. Test the connection:
[Email protected] bin]#/tsql-s server2005-p 1433-u java-p java-d publicdb
Locale is "ZH_CN"
Locale CharSet is "GB2312"
Default database being set to PUBLICDB
1>
This indicates a successful connection! Exit: Quit and exit are OK. Parameter description
-S configured service name
-H Host Name
-P Port
-u username
-p password
-D Database
5. Test query:
#./tsql-s server2005-p 1433-u java-p java-d publicdb1> select User_id,true_name from User_info
2> Go can display Chinese no problem! 6. Let PHP support MSSQL (FREETDS)
Recompile php These parameters are based on your own situation, and here's what we need.
But you have to bring--with-mssql=/usr/local/freetds.
./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-apxs2=/usr/local/apache/bin/apxs-- WITH-GD=/USR/LOCAL/GD--with-jpeg-dir=/usr/local/libjpeg--with-png-dir=/usr/local/libpng--with-zlib-dir=/usr/ Local/zlib--WITH-LIBXML-DIR=/USR/LOCAL/LIBXML2--with-iconv=/usr/local/libiconv--with-freetype-dir=/usr/local/ FreeType--with-pdo-mysql=/usr/local/phpbak/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so-- Enable-sockets--with-curl--with-pear--with-mssql=/usr/local/freetds If compiling an error please do:
# Touch/usr/local/freetds/include/tds.h
# TOUCH/USR/LOCAL/FREETDS/LIB/LIBTDS.A 7.php Test program <?php
/**
* Moit
*
* @author Understand ([email protected]) Date: Wed 05:00:07 GMT 2009
* @copyright Copyright (c) 2009
* @desc Test */$msconnect =mssql_connect ("Server2005", "Java", "Java");
$msdb =mssql_select_db ("publicdb", $msconnect);
$msquery = "Select True_name,user_id,user_name,password from User_info";
$msresults = Mssql_query ($msquery);
while ($row = Mssql_fetch_array ($msresults)) {
echo $row [' user_id ']. "". $row [' True_name ']. " " . $row [' user_name ']. " " .  $row [' PASSWORD ']. "<br>\n";
}
?> 8. I also encountered the need to transcode the problem $author = Iconv (' utf-8 ', ' gb2312 ', $row [' true_name ']);//The name of the publisher of the post Utf-8 turn into gb2312 9. Installation completed, I wish you success!

The problem of using FreeTDS to connect MSSQL Chinese garbled in Linux "reference 1"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.