php读取mssql的ntext字段返回值为空的解决方法_php技巧
本文实例讲述了php读取mssql的ntext字段返回值为空的解决方法。分享给大家供大家参考。具体分析如下:
今天在使用php连接mssql数据库时发现ntext字段的内容无法显示,经过查询发现ntext字段在php中不被支持,解决办法我们只要把ntext字段改成text即可解决了.
如果是表里面没有ntext字段,可以用以下代码:
$link = mssql_connect('KALLESPCSQLEXPRESS', 'sa', 'dsc');
if(!$link || !mssql_select_db('php', $link))
{
die('Unable to connect or select database!');
}
// Do a simple query, select the version of
// MSSQL and print it.
$version = mssql_query('SELECT @@VERSION');
$row = mssql_fetch_array($version);
echo $row[0];
// Clean up
mssql_free_result($version);
?>
如果表里面有ntext字段,且不好修改回text字段,可以如下:
1.修改 php.ini,打开php.ini,找到如下代码:
;mssql.textlimit = 4096 改为 mssql.textlimit = 2147483647
找到:;mssql.textsize = 4096 改为 mssql.textsize = 2147483647
2.可以使用修改字段,由于sql server中,ntext和nvarchar字段是用unicode编码存储内容的,因此php通过mssql扩展读取带ntext和nvarchar类型字段的时候会报错。
如果 title 字段类型为 nvarchar,content 字段类型为 ntext,那么下面的sql语句会报错.
错的代码如下:select title,content from article
正确的:
select convert(varchar(255), title) as title, convert(text, content) as content from article
3.如果你是虚拟主机,可以使用adodb 组件来读取,如果你主机不支持,目前笔者也没办法了,代码如下:
$conn=NewADOConnection('odbc_mssql'); //连接SQL Server数据库
$conn->Connect("Driver={SQL Server};Server=localhost;
Database=mydb;",'username','password');
?>
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

PS "Loading" problems are caused by resource access or processing problems: hard disk reading speed is slow or bad: Use CrystalDiskInfo to check the hard disk health and replace the problematic hard disk. Insufficient memory: Upgrade memory to meet PS's needs for high-resolution images and complex layer processing. Graphics card drivers are outdated or corrupted: Update the drivers to optimize communication between the PS and the graphics card. File paths are too long or file names have special characters: use short paths and avoid special characters. PS's own problem: Reinstall or repair the PS installer.

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

A PS stuck on "Loading" when booting can be caused by various reasons: Disable corrupt or conflicting plugins. Delete or rename a corrupted configuration file. Close unnecessary programs or upgrade memory to avoid insufficient memory. Upgrade to a solid-state drive to speed up hard drive reading. Reinstalling PS to repair corrupt system files or installation package issues. View error information during the startup process of error log analysis.

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

Frequently Asked Questions and Solutions when Exporting PS as PDF: Font Embedding Problems: Check the "Font" option, select "Embed" or convert the font into a curve (path). Color deviation problem: convert the file into CMYK mode and adjust the color; directly exporting it with RGB requires psychological preparation for preview and color deviation. Resolution and file size issues: Choose resolution according to actual conditions, or use the compression option to optimize file size. Special effects issue: Merge (flatten) layers before exporting, or weigh the pros and cons.

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.
