使用php和SQLServer2008将数据库邮件参数传递到存储过程
我想为我的应用程序使用数据库邮件,这意味着我需要将参数传递给存储过程使用php和SQLServer2008将数据库邮件参数传递到存储过程,php,sql-server-2008,stored-procedures,parameters,Php,Sql Server 2008,Stored Procedures,Parameters,我想为我的应用程序使用数据库邮件,这意味着我需要将参数传递给存储过程sp\u send\u dbmail 我有以下代码只是为了测试。但是,我想知道如何使用ssqlserver2008和php将参数传递给存储过程。 仅供参考,我正在使用Microsoft的sqlsrv驱动程序 <?php require_once ('../Connection/connmail.php')?> <?php $sql = "{CALL sp_send_dbmail[[@profile_name
sp\u send\u dbmail
我有以下代码只是为了测试。但是,我想知道如何使用ssqlserver2008和php将参数传递给存储过程。
仅供参考,我正在使用Microsoft的sqlsrv驱动程序
<?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));
?>
任何帮助都将不胜感激我看到这个问题有一段时间没有得到回答,所以这里是解决方案。将您的用户设置为msdb系统数据库中的
databasemailuserrole
$callmailproc = "EXEC msdb.dbo.sp_send_dbmail @profile_name = ?, @recipients=?, @subject=?, @body=?";
$profilename = 'DatabaseMail';
$recipients = 'recipient@domain.com';
$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));
}
$callmailproc = "EXEC msdb.dbo.sp_send_dbmail @profile_name = ?, @recipients=?, @subject=?, @body=?";
$profilename = 'DatabaseMail';
$recipients = 'recipient@domain.com';
$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));
}