2

私はこの方法から日時を取得します:

class DB_Functions extends DB_Connect{

    private $dbConnect = "";
    public $dtime;

    public function __construct() {
        $this->dbConnect = $this->pdo_connect();
        $this->dtime = new DateTime();
    }

    public function destruct() {
        $this->dbConnect = null;
    }


    public function exampleInsert() {
        .
        .
        .
        $result->bindParam(':dateCreation',$this->dtime->format("Y-m-d H:i:s"),PDO::PARAM_STR);
    }
}

次に、dtimeを使用してテーブルに挿入すると、次のようになります。

Line 1708: $result->bindParam(':dateCreation',$this->dtime->format("Y-m-d H:i:s"),PDO::PARAM_STR);

次のエラーを表示します。

<b>Strict Standards</b>:  Only variables should be passed by reference in <b>include\DB_Functions.php</b> on line <b>1708</b><br />

日時を取得する宣言が間違っていますか?

4

1 に答える 1

2

問題はbindParam()、変数をクエリのパラメーターに実際にバインドするものを使用していることです。これは、値を返すメソッド呼び出しではなく、変数でなければなりません。

これにより、次のような使用が可能になります。

$value = 'somevalue';
$result->bindParam(':some_field', $value);
$value = 'someothervalue';
$result->execute(); // executes query with 'someothervalue' passed as parameter.

あなたの場合、使用したいかもしれませんbindValue()。実際には、不変の方法で値をパラメーターにバインドします。それか、フォーマットされた日時を別のクラス変数に保存し、bindParam()その新しい変数で引き続き使用します。

于 2013-02-08T18:39:26.273 に答える