我试图使用php sqlsrv_prepare函数将带有中文字符的html代码插入SQL Server,但是由于未知原因,它不起作用。
这是我的代码:
$sqlInsertMail = "INSERT INTO EnvioCorreo2Temp (CorreoRemitente,CorreoDestinatario,ContenidoID,ContenidoMail,
AsuntoMail,CCOMail,Link,Orden,CuentaID,EnviadorCorreoID,TestigoID,Prioridad,EstatusID,FUA,Activo,Fecha_Lanzamiento)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmtDest = sqlsrv_query($conn, $dest_query);
if($stmtDest){ //This condition is for another query executed before for this "IF" clause
$cont = 0;
while($row = sqlsrv_fetch_array($stmtDest,SQLSRV_FETCH_ASSOC) ) {
$param1 = 'emailaccount@email.com'; $param2 = $row['email']; $param3 = 0; $param4 = $cuerpoMail; $param5 = $companyName;
$param6 = 'emailaccount@email.com'; $param7 = $enclnk; $param8 = 1; $param9 = $CuentaCorreoID['CuentaCorreoID'];
$param10 = 1; $param11 = 0; $param12 = mt_rand(1,1000); $param13 = 4; $param14 = $fdate2; $param15 = 1; $param16 = $date;
$params = array(&$param1, &$param2, &$param3, &$param4, &$param5, &$param6, &$param7, &$param8, &$param9, &$param10, &$param11, &$param12,
&$param13, &$param14, &$param15, &$param16);
try{
if($stmtPrepared = sqlsrv_prepare($conexion, $sqlInsertMail, $params)){
try{
sqlsrv_execute($stmtPrepared);
}catch (Exception $e) {
$bandera = false;
}
}
}catch (Exception $e) {
$bandera = false;
}
}
}else{
if( ($errors = sqlsrv_errors() ) != null) {
$bandera = false;
}
}
此代码尝试插入具有如下文本的变量:
如果您对本次调研有任何问题,请用以下邮箱联系我们:
我尝试了以下操作:
但是,毕竟,我尝试使用简单的sql服务器查询执行:
$sqlInsert = "INSERT INTO cat_textocorreo (idTextos, idIdioma, textoCorreo) VALUES (4, 2000,N'".$mail."')";
$stmtCorreo = sqlsrv_query($conexion, $sqlInsert);
if($stmtCorreo){
echo "YES";
}else{
if( ($errors = sqlsrv_errors() ) != null) {
foreach( $errors as $error ) {
echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
echo "code: ".$error[ 'code']."<br />";
echo "message: ".$error[ 'message']."<br />";
}
}
}
而且难以置信。我真的不明白它是如何工作的。你们中有些人可以帮助我吗?
注意:我的数据库字段在NVARCHAR中
我需要插入中文符号,因为另一个.NET程序将读取此文本以发送电子邮件。而且只有这样的符号才保存在我的数据库中:“åå¹æœ¬æ¬¡è°ƒç”“有任何é-®é¢〜ï