2011-11-12 5 views
0

私のアプリケーションにデータベースメールを使用したいのですが、これはストアドプロシージャにパラメータを渡す必要があることを意味しますsp_send_dbmail 私は次のコードをテスト目的に使用します。私はしかし、SQL Server 2008とPHPを使用してストアドプロシージャにパラメータを渡す方法を知りたい。 FYI私はマイクロソフトphpとsql server 2008を使用して格納されたprcedureにデータベースメールパラメータを渡します

<?php require_once ('../Connection/connmail.php')?> 
<?php 
$sql = "{CALL sp_send_dbmail[[@profile_name='gmailsmtp']]}";//my stored procedure 

    $stmt = sqlsrv_query($conn,$sql)or die(print_r(sqlsrv_errors(),true));  


?> 

からSQLSRVドライバを使用しています上記のコードはエラー

Array ([0] => Array ([0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '{'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '{'.) [1] => Array ([0] => 42000 [SQLSTATE] => 42000 [1] => 105 [code] => 105 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Unclosed quotation mark after the character string '[@profile_name='gmailsmtp']}'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Unclosed quotation mark after the character string '[@profile_name='gmailsmtp']}'.)) 

を生産するすべてのヘルプは

答えて

0

を理解されるであろう私はここで、これはしばらくの間、未回答だった見ています溶液。ユーザーをmsdbシステムデータベースのdatabasemailuserroleにする

$callmailproc = "EXEC msdb.dbo.sp_send_dbmail @profile_name = ?, @recipients=?, @subject=?, @body=?"; 
$profilename = 'DatabaseMail'; 
$recipients = '[email protected]'; 
$subject='Test Message'; 
$body = 'This is the body'; 
$params = array( 
       array($profilename, SQLSRV_PARAM_IN), 
       array($recipients, SQLSRV_PARAM_IN), 
       array($subject, SQLSRV_PARAM_IN), 
       array($body, SQLSRV_PARAM_IN), 
       ); 

/* Execute the query. */ 
$stmt3 = sqlsrv_query($conn, $callmailproc, $params); 
if($stmt3 === false) 
{ 
    echo "Error in executing statement 3.\n"; 
    die(print_r(sqlsrv_errors(), true)); 
} 
関連する問題