所以我有一些数据被发送到数据库,它在某一时刻运行良好,除了添加 .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\\\",\\\"响应
格式。切换到不再支持魔术引号的php 5.6后,数据保存正确,不再有问题
关于php - 添加 .htaccess 文件后,mysql 数据库不再接收数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39500743/