0

我正在尝试用开发电子邮件地址替换电子邮件地址,以便测试我的电子邮件发送功能。

下面的功能导致我的网页停止响应,当我尝试查看 SQL Server Management 2008 中的表时,我无法。我相信问题出在线路上

$scrub = sqlsrv_query($conn, "UPDATE " . $tName . " SET DCAEmail='test@test.edu'");

不过,我不确定。整个功能:

function scrubEmail($conn){
   $tableNameList = array();
   $getTableName = sqlsrv_query($conn, "Select Name FROM sys.tables");
   while($row = sqlsrv_fetch_array($getTableName)){
      if($row['Name'] !== "sysdiagrams"){
        $tableNameList[] .= $row['Name'];   
      } 
    }

    foreach($tableNameList as &$tName){
        $hasDCAEmail = sqlsrv_query($conn,  "SELECT DCAEmail from " . $tName  );
        if($hasDCAEmail){
            $scrub = sqlsrv_query($conn, "UPDATE " . $tName . " SET DCAEmail='test@test.com'");
            if(!$scrub){
                die( print_r( sqlsrv_errors(), true));
            }
        }
    }
}
4

1 回答 1

0

感谢 Raidenance 的帮助,我想通了!完整代码如下。在执行新查询之前,我需要提交 sql_srv 查询。

function scrubEmail($conn){
   $tableNameList = array();
   $getTableName = sqlsrv_query($conn, "Select Name FROM sys.tables");
   while($row = sqlsrv_fetch_array($getTableName)){
        if($row['Name'] !== "sysdiagrams"){
            $tableNameList[] .= $row['Name'];   
        }
   }

    foreach($tableNameList as &$tabName){
        if ( sqlsrv_begin_transaction( $conn ) === false ) {
            die( print_r( sqlsrv_errors(), true ));
        }
        $hasFIELD = sqlsrv_query($conn,  "SELECT COLUMNNAME from " . $tabName  );
        if($hasFIELD){
        }
        else {
            sqlsrv_rollback( $conn );
            echo "hasFIELD Transaction rolled back.<br />";
        }

        while($row = sqlsrv_fetch_array($hasDCAEmail)){
            $scrub = sqlsrv_query($conn, "UPDATE " . $tabName . " SET COLUMN='test@test.edu'");
            if($scrub){     
                sqlsrv_commit( $conn );
                echo "Transaction committed.<br />";
            }
            else {
                sqlsrv_rollback( $conn );
                echo "Transaction rolled back.<br />";
            }           
        }
    } 
 }
于 2013-04-30T18:08:56.720 回答