1

これは一日中私を夢中にさせていました-今、私は助けが必要です....

データベースにデータを挿入する 2 つの方法を試しましたが、どちらも今まで見たことのない方法で失敗しました。

- を使用するだけmysqli->query("...")で、mysqld.general.log に見られるように、実際のクエリの末尾にカンマが付きます。フィールドと同じ数の余分なカンマがあります。

メソッドを使用するmysqli->prepareと、実際の準備ステートメントがログに表示されます。

ログに表示される内容とともに、以下にコードを含めます。

グローバル $mysqli オブジェクトは、最初にインクルード ファイルに作成されます。これは、select ステートメントが正常に機能するため、確実に機能します...

どんな助けでも大歓迎です。

コード:-

function addplaces($placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire)
{
 global $mysqli;

 $mysqli->query("INSERT INTO `places` (`placeID`,`placename`,`easting`,`northing`,`latitude`,`longitude`,`parish`,`inuse`,`shire`) VALUES ($placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire)");

}

ログ出力:-

9594 Query INTO places ( placeID, placename, easting, northing, latitude, longitude, parish, ) VALUES ("12672" inuse, shire"Accrington","375500","428500","53.752300262451","-2.3730099201202","Accrington","1",ランカシャー,,,,,,,,) 9594 やめる

コード:-

function addplaces($placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire)
{
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO places (placeID,placename,easting,northing,latitude,longitude,parish,inuse,shire) VALUES (?,?,?,?,?,?,?,?,?)") or die ("Could not Prepare Statement");
$stmt->bind_param('sssssssss', $placeID,$placename,$easting,$northing,$latitude,$longitude,$parish,$inuse,$shire );
$stmt->execute();
}

ログ出力:-

9595 準備 INSERT INTO 場所 ( placeID, placename, Easting, Northing, latitude, longitude, parish, inuse, shire ) VALUES (?,?,?,?,?,?,?,?,?) 9595 stmt を閉じる 9595 Quit

値フィールドを一重引用符と二重引用符で囲んでみましたが、それでも同じ結果が得られます...

また、これは私の最初の投稿なので、まだこのエディターのこつを持っているかどうかわからないので、間違っている場合はご容赦ください..

4

1 に答える 1