繁体   English   中英

PHP将报告MSSQL查询表的状态选择为

[英]PHP to report status of MSSQL query table select into

我有一个按钮:

<a href="#" onclick="loadPage('admin_manualsend.php?refresh=true'); return false;">
    <i class="fa fa-refresh"></i> 1. Refresh Now
</a>

并在单击时加载同一页面,它是带有refresh = true的页面,因此现在在页面加载时将触发以下内容:

if(isset($_GET["refresh"]) && $_GET["refresh"]=="true"){
    $res = db_query("begin try drop table [TmpTable] end try begin catch end catch");
    $res = db_query("SELECT * INTO [TmpTable] FROM [dbo].[ViewLive]");
}

需要一些时间,我希望它报告表删除是否成功,并且还报告它现在正在传输的记录的计数,然后报告完成的时间,如下所示:

if(isset($_GET["refresh"]) && $_GET["refresh"]=="true"){
    $res = db_query("begin try drop table [TmpTable] end try begin catch end catch");
    Show modal, echo 'Drop done'; (or drop failed)
    WHILE ( $res = db_query("SELECT * INTO [TmpTable] FROM [dbo].[ViewLive]");
    echo 'Count of current record' 
    count of record +1
    )
    echo 'Update done'; 
    (user can then close modal)
}

我该怎么做? 我使用:PHP,MSSQL,脚本src =“ // ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”>

谢谢

更新:

    function db_query($query) {
    global $conn;
    $res = sqlsrv_query($conn, $query);
    return $res;
}

function db_fetch_array($res) {
    $result = array();
    while( $array = sqlsrv_fetch_array($res) ) {
          $result[count($result)] = $array;    
    }  
    sqlsrv_free_stmt($res);
    return $result;
}

function db_fetch_row($res) {                   
    $array = sqlsrv_fetch_array($res);
    sqlsrv_free_stmt($res);
    return $array;
}

function db_fetch_one($res) {                   
    $array = sqlsrv_fetch_array($res);
    sqlsrv_free_stmt($res);
    return $array[0];

我不确定您要做什么,但是如果您使用ajax,则可以在不离开页面的情况下执行sql并获得成功或错误的回调!

 // put this in your document ready function for index.html $("#submit").on("click", function() { $.ajax({ type: "post", url: "process.php", data: "action=SomeActionHere", success: function(data) { alert("SUCCESS"); }, error: function(e) { alert("ERROR"); } }); }; 
 <!--index.html --> <button id="submit">GOGO</button> <!--process.php--> <?php header("Content-type: application/json; charset=utf-8"); //connect to the server $action = $_POST['action']; if($action == "SomeActionHere"){ // do you sql stuff here // when done sql echo json_encode("SUCCESS"); // whatever data you want to send back } ?> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM