douwayuan3063 2017-06-20 23:12
浏览 50

用雄辩的预备语句创建用户

I would like to create a database user using something like the following prepared statement:

DB::statement("CREATE USER ? IDENTIFIED BY ?", ['abc', 'def']);

However, attempting to run this gives me an error:

SQLSTATE[42000]: Syntax error or access violation: 1064 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 '? IDENTIFIED BY ?' at line 1 (SQL: CREATE USER abc IDENTIFIED BY def)

I can create like this:

DB::statement("CREATE USER {$user} IDENTIFIED BY {$password}");

But I would prefer not to use a prepared statement, how can I achieve that?

  • 写回答

1条回答 默认 最新

  • douyiyang6317 2017-06-20 23:17
    关注

    Try the following:

    DB::statement("CREATE USER :name IDENTIFIED BY :password;", ['name' => 'abc', 'password' => 'def']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测