添加.htaccess文件后,mysql数据库不再接收数据?

时间:2016-09-14 22:43:27

标签: php mysql apache .htaccess

所以我有一些发送到数据库的数据,它在某一点上运行良好,除了添加.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

不知道还能做什么?

1 个答案:

答案 0 :(得分:0)

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

相关问题