何らかの理由で、php 経由で実行すると失敗する SQL 挿入がいくつかありますが、phpmyadmin に直接貼り付けた場合は失敗しません。
PHPコードは次のとおりです。
private function createMockAccount($email){
$passwordHash=$this->nonce();
$query='insert into GeneralUser(email,password,isTemp) values("'.$email.'","'.$passwordHash.'",1);';
$query=$query.'insert into ContentUser(email) values("'.$email.'");';
error_log("executing the following query to create mock accounts: ".$query);
$database=mysqli_connect(host,username,password,dbName);
if (mysqli_connect_errno()) {
error_log("Connect failed: ".mysqli_connect_error());
}
if(!mysqli_query($database,$query)){
error_log("Errormessage:".mysqli_error($database));
}
return $passwordHash;
}
実行すると、エラー ログに次のように表示されます。
[11-Aug-2013 04:20:42 America/Denver] executing the following query to create mock accounts: insert into GeneralUser(email,password,isTemp) values("suxhfisk@guerrillamail.biz","D0Obkg/Lue+4AFSAzinqdo/XAAwDhMfitmnm53R0RwA=",1);
insert into ContentUser(email) values("suxhfisk@guerrillamail.biz");
[11-Aug-2013 04:20:42 America/Denver] Errormessage:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into ContentUser(email) values("suxhfisk@guerrillamail.biz")' at line 2
また、次の方法で mysqli_real_escape_string を使用してみましたが、役に立ちませんでした。
$query=mysqli_real_escape_string($database,$query);
それで、error_logにはまだ同じエラーが表示されます...
[11-Aug-2013 04:51:42 America/Denver] executing the following query to create mock accounts: insert into GeneralUser(email,password,isTemp) values("suxhfisk@guerrillamail.de","guR8Sps8e4Iv1LBXmsREH2GVd+WH/cH1Nx/zy9VOnLE=",1);
insert into ContentUser(email) values("suxhfisk@guerrillamail.de");
[11-Aug-2013 04:51:42 America/Denver] Errormessage:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\"suxhfisk@guerrillamail.de\",\"guR8Sps8e4Iv1LBXmsREH2GVd+WH/cH1Nx/zy9VOnLE=\",1' at line 1
ばかげた何かが欠けていると確信していますが、どちらの場合も、error_log からの文字列が phpmyadmin に直接コピーされると、正常に実行されます。
どんな助けでも大歓迎です、ありがとう!:)