所以这个问题可能是很多事情中的一个。这是我的情况。
我使用ec2服务器作为我的主机网站,它通过机架空间负载均衡器连接到机架空间数据库(它们不允许从机架空间以外的数据源连接到数据库)。
无论如何,我的问题是我正在尝试在插入时编码我的mysql表并在选择时对其进行解码。这是我用来插入的代码:
function mysql_insert_sanitize_encrypt_store($databaseName,$names,$values,$link){
$query="INSERT INTO ".$databaseName." (";
foreach($names as $name){
$query=$query.$name.",";
}
$query[strlen($query)-1]=")"; //replace trailing comma with parenthesis
$query=$query." VALUES (";
foreach($values as $value){
$sanivalue=filter_var($value,FILTER_SANITIZE_URL);
$query=$query."ENCODE('".$sanivalue."','encryptionstring'),";
}
$query[strlen($query)-1]=")";
echo $query;
if(mysql_query($query,$link)){
return 1;
}
}
生成如下查询:
INSERT INTO PublishedItems (PublisherUrl,Age,option,experience,goals,gender,minstaken,Item) VALUES (ENCODE('https://www.google.com/profiles/100571329423938175195','encryptionstring'),ENCODE('18-30,30-45','encryptionstring'),ENCODE('15-30','encryptionstring'),ENCODE('novice,amateur','encryptionstring'),ENCODE('Loseweight','encryptionstring'),ENCODE('male','encryptionstring'),ENCODE('120','encryptionstring'),ENCODE('[[{"name":"MW350","value":""},{"name":"MD350","value":""}]]','encryptionstring'))
,这将成功插入。
当我尝试再次获取数据时,我使用以下代码:
$query="select ".$decryptionQueries[$count++]." FROM ".$DBName;
mysql_free_result($result);
$result=mysql_query($query,$link);
echo "</br>";
echo $query;
echo "</br>";
echo "decrypted result --->";
var_dump($result);
echo "</br>";
echo "</br>============".$DBName."============UNENCRYPTED=========</br>";
while($row=mysql_fetch_array($result)){
echo "</br>";
var_dump($row);
echo "</br>";
echo "<pre>" . print_r(get_defined_vars(),true) . "</pre>";
}
其中解密查询定义如下:
$ decryptionQueries=array("DECODE(PublisherUrl, 'encryptionstring'), DECODE(Age,'encryptionstring'), DECODE(option,'encryptionstring'), DECODE(experience,'encryptionstring'), DECODE(goals,'encryptionstring'), DECODE(gender,'encryptionstring'),DECODE(minstaken,'encryptionstring'), DECODE(Item,'encryptionstring')","DECODE(User,'encryptionstring'), DECODE(Age,'encryptionstring'), DECODE(option,'encryptionstring'), DECODE(experience,'encryptionstring'), DECODE(goals,'encryptionstring'),DECODE(gender,'encryptionstring'), DECODE(Injuries,'encryptionstring'), DECODE(availperday,'encryptionstring'), DECODE(Item,'encryptionstring')");
这会生成如下查询:
select DECODE(PublisherUrl, 'encryptionstring'), DECODE(Age,'encryptionstring'), DECODE(option,'encryptionstring'), DECODE(experience,'encryptionstring'), DECODE(goals,'encryptionstring'), DECODE(gender,'encryptionstring'),DECODE(minstaken,'encryptionstring'), DECODE(Item,'encryptionstring') FROM PublishedItems
但是在显示数据时,rows变量的已定义变量条目如下所示:
[row] => Array
(
[0] => h
[DECODE(PublisherUrl, 'encryptionstring')] => h
[1] => 18-3
[DECODE(Age,'encryptionstring')] => 18-3
[2] => 15-3
[DECODE(option,'encryptionstring')] => 15-3
[3] =>
[DECODE(experience,'encryptionstring')] =>
[4] =>
[DECODE(goals,'encryptionstring')] =>
[5] => male
[DECODE(gender,'encryptionstring')] => male
[6] => 1
[DECODE(minstaken,'encryptionstring')] => 1
[7] => [
[DECODE(Item,'encryptionstring')] => [
我的问题是:为什么这只返回存储在数据库中的部分字符串?或者为什么它只存储部分字符串?我的代码出了什么问题?它与编码和解码有关吗?
当输入没有先编码而只是从数据库中选择时,它会正确且完整地返回,所以我认为它与编码和解码有关。
您认为这是什么问题?
编辑:
迭代其中一个表的行会得到以下输出(我只是var_dumped行)
============PublishedItems============ENCRYPTED=========
array(9) { ["PublisherUrl"]=> string(1) "A" ["Age"]=> string(3) "7b?" ["option"]=> string(3) "7C?" ["experience"]=> string(0) "" ["goals"]=> string(0) "" ["gender"]=> string(4) " ¬'" ["minsTaken"]=> string(1) "7" ["Item"]=> string(1) "-" ["DateSubmitted"]=> string(19) "2012-09-14 21:05:57" }
array(9) { ["PublisherUrl"]=> string(1) "A" ["Age"]=> string(3) "7b?" ["option"]=> string(3) "7C?" ["experience"]=> string(0) "" ["goals"]=> string(1) " " ["gender"]=> string(5) " ¬'#" ["minsTaken"]=> string(1) "7" ["Item"]=> string(1) "-" ["DateSubmitted"]=> string(19) "2012-09-14 21:10:41" }
array(9) { ["PublisherUrl"]=> string(1) "A" ["Age"]=> string(3) "7b?" ["option"]=> string(3) "7C?" ["experience"]=> string(0) "" ["goals"]=> string(1) " " ["gender"]=> string(5) " ¬'#" ["minsTaken"]=> string(1) "0" ["Item"]=> string(1) "-" ["DateSubmitted"]=> string(19) "2012-09-14 21:16:55" }
array(9) { ["PublisherUrl"]=> string(1) "A" ["Age"]=> string(3) "7b?" ["option"]=> string(3) "7C?" ["experience"]=> string(0) "" ["goals"]=> string(1) " " ["gender"]=> string(4) " ¬'" ["minsTaken"]=> string(1) "7" ["Item"]=> string(1) "-" ["DateSubmitted"]=> string(19) "2012-09-14 22:34:14" }
array(9) { ["PublisherUrl"]=> string(53) "https://www.google.com/profiles/100571329423938175195" ["Age"]=> string(3) "45+" ["option"]=> string(7) "below15" ["experience"]=> string(6) "novice" ["goals"]=> string(10) "Loseweight" ["gender"]=> string(4) "male" ["minsTaken"]=> string(3) "120" ["Item"]=> string(59) "[[{"name":"MW484","value":""},{"name":"MD484","value":""}]]" ["DateSubmitted"]=> string(19) "2012-09-14 22:49:41" }
array(9) { ["PublisherUrl"]=> string(53) "https://www.google.com/profiles/100571329423938175195" ["Age"]=> string(3) "45+" ["option"]=> string(8) "below15," ["experience"]=> string(6) "novice" ["goals"]=> string(10) "Loseweight" ["gender"]=> string(4) "male" ["minsTaken"]=> string(3) "120" ["Item"]=> string(117) "[[{"name":"MW310","value":""},{"name":"MD310","value":""}],[{"name":"MW900","value":""},{"name":"MD900","value":""}]]" ["DateSubmitted"]=> string(19) "2012-09-14 22:50:19" }
array(9) { ["PublisherUrl"]=> string(1) "A" ["Age"]=> string(2) "vS" ["option"]=> string(0) "" ["experience"]=> string(0) "" ["goals"]=> string(0) "" ["gender"]=> string(4) " ¬'" ["minsTaken"]=> string(1) "7" ["Item"]=> string(1) "-" ["DateSubmitted"]=> string(19) "2012-09-14 23:50:32" }
请注意,有些字符串未加密,我将其作为控件执行,这表明编码插入是问题所在,但我无法想象插入的查询字符串如何(请参阅第二个代码片段)只会插入部分信息。解密后,这些字符串会给出部分字符串,如果完整的话,它将是正确的。
此外,这是表格的声明:
create table PublishedItemss (PublisherUrl char(150),Age char(5),option char(8),experience char(20), goals char(50), gender char(8), minsTaken int, item TEXT,DateSubmitted timestamp NOT NULL DEFAULT NOW())';