因此,我有一些数据已发送到数据库,并且它在某一点上运行良好,当我查看页面以查看发生了什么时,除了添加.htaccess文件外,什么都没有改变。

NULL
Invalid query:


用我的凭据指向我的数据库的php文件是:

<?php

$dbc = mysql_connect('localhost', 'my_user', 'my_password');
mysql_select_db('mydatabase', $dbc);

?>


和发送数据的文件:

<?php
include('/path/to/fileabove.php');

function mysql_insert($table, $inserts) {
    $values = array_map('mysql_real_escape_string', array_values($inserts));
    $keys = array_keys($inserts);

    return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}

// get the table name
$tab = $_POST['table'];

// decode the data object from json
$trials = json_decode($_POST['json']);

// get the optional data (decode as array)
$opt_data = json_decode($_POST['opt_data'], true);
$opt_data_names = array_keys($opt_data);

var_dump($trials);

// for each element in the trials array, insert the row into the mysql table
for($i=0;$i<count($trials);$i++)
{
    $to_insert = (array)($trials[$i]);
// add any optional, static parameters that got passed in (like subject id or condition)
    for($j=0;$j<count($opt_data_names);$j++){
        $to_insert[$opt_data_names[$j]] = $opt_data[$opt_data_names[$j]];
    }
    $result = mysql_insert($tab, $to_insert);
}

// confirm the results
if (!$result) {
    die('Invalid query: ' . mysql_error());
} else {
    print "successful insert!";
}

?>


在我的error_log文件中,我看到:

PHP Warning:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in /path/to/savedata.php on line 33


经过一番搜索,我发现了这篇文章:

http://galleryproject.org/node/57633

所以我尝试将其添加到.htaccess文件中,然后检查了一下,看来我的主机继续进行并对其进行了更改:

# File modified on Wed Sep 14 16:28:37 2016 by server
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
# php_value session.cookie_domain http://mydomain


不知道该怎么办??

最佳答案

问题似乎是,添加.htaccess文件触发了php配置中的一些更改,以设置魔术引号,这就是\"\\\"rt\\\",\\\"responses格式的原因。切换到不再支持魔术引号的php 5.6之后,数据可以正确保存,并且不再存在问题

关于php - 添加.htaccess文件后,mysql数据库不再接收数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39500743/

10-15 17:31
查看更多