在MySQL数据库中存储PHP数组的内容 [英] Storing contents of a PHP array in a MySQL database

查看:119
本文介绍了在MySQL数据库中存储PHP数组的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在mysql中存储数组内容 我正在使用下面的代码

I am having trouble storing array contents in mysql I am using the code below

foreach($found_entry as $key => $sd) {
         echo "$key => $sd <br>";
$insert_found_row = mysql_query("INSERT INTO myTable values ID = \"$sd[0]\" ,Folder = \"NULL\", Tsi = \"$sd[11]\", PT= \"NA\" ") or die(mysql_error());  
            echo "$sd";

如果我回显我得到的值

0 => ST10928
1 =>
2 => 2010-02-19 03:37:16
3 => \\fs1\
4 =>
5 =>
6 =>
7 =>
8 => M1
9 =>
10 =>
11 => LOG1.TXT 

推荐答案

您的查询语法错误.使用SET代替VALUES.另外,您可能根本不需要foreach循环,因为您同时引用了$sd[0]$sd[11].尝试这样的事情:

Your query syntax is wrong. Use SET instead of VALUES. Also, you probably don't need the foreach loop at all, as you are referencing both $sd[0] and $sd[11]. Try something like this:

$query = sprintf("INSERT INTO
             myTable
         SET
             ID = '%s',
             folder = NULL,
             Tsi = '%s',
             PT = 'NA'",
             mysql_real_escape_string($found_entry[0]),
             mysql_real_escape_string($found_entry[11])
         );

mysql_query($query) or die(mysql_error());

这篇关于在MySQL数据库中存储PHP数组的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆