Thinkphp MsSQL operations

Source: Internet
Author: User
Before Thinkphp's MsSQL operations, he has introduced the installation of MsSQL extension in Linux in detail in the blog of PHP programmer Lei Xuesong. I thought that after this solution, ThinkPHP, which is an excellent PHP framework in China, should be smooth. However, you still encountered some problems when connecting to the MsSQL Database. there are not many online solutions. The PHP programmer Lei Xuesong will summarize the MsSQL database errors and solutions in the ThinkPHP project and share them with friends who need them.

1. Error "Undefined class constant 'pdo: SQLSRV_ATTR_ENCODING"

The specific solution is:Comment out line 'pdo: SQLSRV_ATTR_ENCODING => PDO: SQLSRV_ENCODING_UTF8 and 'in ThinkPHP \ Library \ Think \ Db \ Driver \ Sqlsrv. class. php.

2. Error "SQLSTATE [IMSSP]: An unsupported attribute was designated on the PDO object"

The specific solution is:Comment out line 101st '$ this-> options [PDO: ATTR_EMULATE_PREPARES] = false' in ThinkPHP \ Library \ Think \ Db \ Driver. class. php.

3. if the original table name is too large to be written, an error will be reported and the table name cannot be found.

The specific solution is:All table names in the ThinkPHP project are in lowercase regardless of whether the table names in the MsSQL database are in lowercase.

The configuration file conf. php for MsSQL operations in ThinkPHP3.2 is attached below:

Returnarray (

// 'Config maps '=> 'configuration value'

'Db _ type' => 'sqlsrv', // Database TYPE

'Db _ user' => '', // USER name

'Db _ pwd' => '', // password

'Db _ port' => '', // PORT

'Db _ prefix' => '', // database table PREFIX

'Db _ DSN '=> 'dblib: host = IP Address: Port; dbname = database name ',

'Db _ charset' => 'utf8', // character set

);

In this project, the first time I used the ThinkPHP framework to operate the MsSQL database was not smooth. However, I still learned a lot and summarized some truth. First, if you have a real understanding, you will know if you have tried it. this is too important for PHP programmers. errors may occur in different environments and systems. Second, in the face of new problems, we must be patient, confident, and determined. Clarify the principles and resolve the problems as your own knowledge points. Third, you must recognize yourself and no one can do anything. No matter how long you have been a PHP programmer, you will always encounter problems. Be sure to communicate with others, use the power of the outside, and read more online materials. Finally, I would like to thank ThinkPHP developers and their predecessors who have contributed to the open-source business!

Tags:PHP programming

Source:Thinkphp MsSQL operations

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.