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 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动