嗨,我正在使用 Faker 库生成随机数据来填充我正在处理的项目的表,如您所见,我正在准备语句,然后在数组中设置语句的所有变量。最后我正在执行该声明,但注意到发生任何想法为什么它让我非常困惑。
<?php
require('/vendor/autoload.php');
//Create New Instance Of Faker
$faker = Faker\Factory::create();
//Connect to Database
$conn = connect();
for ($i=1; $i < 10; $i++){
$query = "INSERT INTO nightsout_venues (name, type, descripton , username)
VALUES(:name, :type, :descripton, :username)";
$stmt = $conn->prepare($query);
$Type = array("restaurant","pub","club","cafe");
$randomtype = array_rand($Type);
//Creating Array Of values
// For Prepared Statement
$arg =
array(
':name' => $faker -> company,
':type' => $Type[$randomtype],
':descripton' => $faker -> paragraph(5),
':username' => $faker -> freeemail,
);
//Executing the statement
$stmt->execute($arg);
}
?>
非常感谢马特