Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php和SQLServer2008将数据库邮件参数传递到存储过程_Php_Sql Server 2008_Stored Procedures_Parameters - Fatal编程技术网

使用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));
}