如何在新列中的每个部分插入逗号分隔的字符串到SQL Server表中

时间:2021-02-21 00:24:11

Example:

$words = 'word1,word2,word3';

Ouput:

id    value1  value2 value3
---   ------  ------ -------
1     word1   word2  word3

I want the data to be inserted in a single row but in different columns

我希望数据插入一行但在不同的列中

This is what I have tried so far:

这是我到目前为止所尝试的:

$data = '"1","1","8009","8989"';
$stmt = odbc_prepare($con," INSERT INTO stock( SiteId, DatabaseId, Code, Category) VALUES(?,?,?,?)");
$success = odbc_execute($stmt,array($data) );
odbc_close($con);

1 个解决方案

#1


1  

use explode function

使用爆炸功能

<?php
$words = 'word1,word2,word3';

$data_array = explode(',', $words);

    $a=$data_array[0];
    $b=$data_array[1];
    $c=$data_array[2];
    //insert Qquery here.
?>

#1


1  

use explode function

使用爆炸功能

<?php
$words = 'word1,word2,word3';

$data_array = explode(',', $words);

    $a=$data_array[0];
    $b=$data_array[1];
    $c=$data_array[2];
    //insert Qquery here.
?>