PDO bindParam变成一条语句?

编程入门 行业动态 更新时间:2024-10-15 04:23:39
本文介绍了PDO bindParam变成一条语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法将这些bindParam语句放入一条语句中?

Is there a way I can put these bindParam statements into one statement?

$q = $dbc -> prepare("INSERT INTO accounts (username, email, password) VALUES (:username, :email, :password)"); $q -> bindParam(':username', $_POST['username']); $q -> bindParam(':email', $_POST['email']); $q -> bindParam(':password', $_POST['password']); $q -> execute();

我使用的是在可能的情况下准备的mysqli,我切换到PDO以获得assoc_array支持.在PDO的php网站上,它们以单独的行显示,在所有示例中,我都看到它以单独的行显示.

I was using mysqli prepared before where it was possible, I switched to PDO for assoc_array support. On the php website for PDO it shows them on seperate lines, and in all examples I have seen it is on seperate lines.

有可能吗?

推荐答案

execute 页面就是您想要的:

Example 2 on the execute page is what you want:

$sth->execute(array(':calories' => $calories, ':colour' => $colour));

您可能还想看看其他示例.带有问号参数,它将是:

You may want to look at the other examples too. With question mark parameters, it would be:

$q = $dbc -> prepare("INSERT INTO accounts (username, email, password) VALUES (?, ?, ?)"); $q->execute(array($_POST['username'], $_POST['email'], $_POST['password']));

如果只有这些列,您可以编写:

If those are the only columns, you can just write:

$q = $dbc -> prepare("INSERT INTO accounts VALUES (?, ?, ?)"); $q->execute(array($_POST['username'], $_POST['email'], $_POST['password']));

更多推荐

PDO bindParam变成一条语句?

本文发布于:2023-11-12 19:54:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   PDO   bindParam

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!