dongxun1142 2014-12-01 00:37
浏览 59
已采纳

faker库和Prepared Statement不工作没有显示错误

hi I am using the Faker library to generate random data to populate a table for a project I am working on, as you can see I am preparing the statement then setting all the variables for the statement in a array. finally I am executing the statement, Yet Noting happens any idea why its got me very confused.

<?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);   
}
?>

many thanks in advance Matt

  • 写回答

1条回答 默认 最新

  • dongshao5573 2014-12-01 12:32
    关注

    As per OP's wish,

    Make sure you haven't made a typo error for "descripton", if your column is called "description".

    As far as I can tell, your code looks good to me.

    Plus, quoting Ghost in regards to error exceptions:

    "make sure PHP's error reporting is turned on, and add $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); after $conn".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集