dongxiongshi9952 2015-02-23 18:29
浏览 67
已采纳

如何使用PHP增加MSSQL表列中的字符数

Currently, I have a table column that has a text limit of 255 (Varchar[255]), I would like the number of characters increased to 4000 or more. What would the code be, if ran through a PHP page, to make this modification?

Note* - I have modified a column with a varchar(100) to varchar(255), it seems that my columns cannot exceed a varchar of 255.

So far I have used this - alas, it doesn't work:

<?php
$dbhost = 's036';
$dbuser = 'rost';
$dbpass = 'rosword';
 $conn=mssql_connect('smtscom','sTrsr','Rsa');
mssql_select_db('Gsa',$conn);
if(! $conn )
{
  die('Could not connect: ' . mssql_get_last_message());
}
echo 'Connected successfully';
$sql = "ALTER TABLE new_tders2 ALTER 

COLUMN description varchar(4000)";

mssql_select_db('Gsa');
$retval = mssql_query( $sql, $conn );
if(! $retval )
{
  die('Could not create table:');
}
echo "Table column modified successfully
";
mssql_close($conn);
?>

When I run the PHP page (the code above), it says "Table column modified successfully", but I still can only input 255 characters into the column.

  • 写回答

1条回答 默认 最新

  • dsriya5471 2015-02-23 20:22
    关注

    I figured it out - instead of using VARCHAR(4000), use TEXT. It will exceed 4000 characters, and allow up to 64 Kb, 2 bytes overhead. However, this is fine in my case, as more than 4000 characters is fine for this part of the website.

    Here is the new (working) code:

    <?php
    $dbhost = 's036';
    $dbuser = 'rost';
    $dbpass = 'rosword';
     $conn=mssql_connect('smtscom','sTrsr','Rsa');
    mssql_select_db('Gsa',$conn);
    if(! $conn )
    {
      die('Could not connect: ' . mssql_get_last_message());
    }
    echo 'Connected successfully';
    $sql = "ALTER TABLE new_tders2 ALTER 
    
    COLUMN description TEXT";
    
    mssql_select_db('Gsa');
    $retval = mssql_query( $sql, $conn );
    if(! $retval )
    {
      die('Could not create table:');
    }
    echo "Table column modified successfully
    ";
    mssql_close($conn);
    ?>
    

    Thank you to all those that tried to answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图