开发者

How can I insert an associative array into sql?

This is my array:

[abominado] => Array
    (
        [0] => réprobo
        [1] => réprobo
        [2] => abominado
        [3] => banido
        [4] => condenado
        [5] => detestado
        [6] => odiado
        [7] => precito
        [8] => renegado
        [9] => repudiado
    )

[abominar] => Array
    (
        [0] => repelir
        [1] => repelir
        [2] => abominar
        [3] => afastar
        [4] => afugentar
        [5] => arredar
        [6] => desalojar
        [7] => desviar
        [8] => detestar
        [9] => empuxar
        [10] => escorraçar
        [11] => espinafrar
        [12] => execrar
        [13] => exercer
        [14] => expulsar
        [15] => grimpar
        [16] => impugnar
        [17] => odiar
        [18] => rebater
        [19] => rechaçar
        [20] => recusar
        [21] => rejeitar
        [22] => relegar
        [23] => repudiar
    )

how can I 开发者_StackOverflow中文版insert it into sql ?


foreach ($abominado as $key=>$str)
{
    $string .= "$key:$str\n";
}

mysql_query("INSERT INTO strings VALUES ('".mysql_real_escape_string($string)."')");


You can use serialize to cast it to string and unserialize when you get it


First, these arrays happen to be sequential.

Second, in a SQL table, any column can be used as a search criteria, so just insert the data directly and set up an index on any searchable column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜