2017-01-27 6 views
0

私はPHPを試していて準備済みのステートメントで苦労しています。私は次のコードMySQLのPDO作成済みステートメント

<?php 
require_once 'dbconfig.php'; 


try { 
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); 
    echo "Connected to $dbname at $host successfully."; 
} catch (PDOException $pe) { 
    die("Could not connect to the database $dbname :" . $pe->getMessage()); 
} 

$statement = $conn->prepare("SELECT * FROM voicemessages WHERE dir = :dir"); 
$statement->bindParam("dir", "test"); 

$statement->execute(); 
$statement->setFetchMode(PDO::FETCH_ASSOC); 
?> 

しかし、次のエラーを取得して持っている :

Connected to voicemail1 at 192.168.1.121 successfully. 
Warning: main(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for 'GMT/0.0/no DST' instead in /var/lib/asterisk/agi-bin/KesherVoicemail.php on line 13 

Fatal error: Cannot pass parameter 2 by reference in /var/lib/asterisk/agi-bin/MyScript.php on line 13 

ライン13は、bindParamラインです。

誰かが間違っていることを説明できますか?

+0

する必要があり、あなたは自分のクラスファイルに( '' * SELECT)クエリのすべてを配置する必要があります。 – Option

答えて

1

bindParam関数を参照してパラメータ2を渡す必要があります。

あなたのエラーはここにあるdoc

variable: Name of the PHP variable to bind to the SQL statement parameter.

+1

あなたの答えはまだincorect –

+1

右..コロンを逃した。それをチェックしていただきありがとうございます! – xRahul

2

をチェックthis-

$test = "test"; 
$statement->bindParam(":dir", $test); 

でthis-

$statement->bindParam("dir", "test"); 

を交換してください:$statement->bindParam("dir", "test");

が提案としてbindParam(":Placeholder",$variable)

<?php 
require_once 'dbconfig.php'; 


try { 
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); 
    echo "Connected to $dbname at $host successfully."; 
} catch (PDOException $pe) { 
    die("Could not connect to the database $dbname :" . $pe->getMessage()); 
} 
$test = "test"; 

$statement = $conn->prepare("SELECT * FROM voicemessages WHERE dir = :dir"); 
$statement->bindParam(":dir", $test); 

$statement->execute(); 
$statement->setFetchMode(PDO::FETCH_ASSOC); 
?> 
関連する問題