PHP和Microsoft SQL Server的存储过程

时间:2017-03-16 03:36:08

标签: php sql-server stored-procedures pear

我正在寻找一个使用PHP和MSSQL(存储过程)的项目解决方案..我希望任何人都可以帮我修复它。这是我的PHP代码..我现在想要做什么来注册用户函数..我的存储过程:sp_register_info

<?php
    session_start();

    header('Content-type: text/json');
    header("Cache-Control: no-cache, must-revalidate");

    $name = $_REQUEST['data1'];
    $email = $_REQUEST['data2'];


    MSSQL();
    register_user($name,$email);

    function MSSQL(){
        require_once "../myDB.php";
            Connect_MSSQL();
    }

    function register_user($name,$email) {

            global $DBIn;

            $query =    "DECLARE @UserID varchar(20)".
                        "DECLARE @Name varchar(20)".
                        "DECLARE @Email varchar(200)".
                        "SET @Name = $name".
                        "SET @Email  = $email".
                        "EXEC sp_register_info @Name, @Email,@UserID OUTPUT".
                        "select @UserID";

            $data = array($name,$email);  

            $res =& $DBIn->query($query,$data);

            if ($res->numRows() > 0) {

                    while($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)){
                            $UserID = $row['UserID'];
                    }
                    loadSuccess(UserID); 
            }

            else {

                    loadFailed();
            }

    }


    function loadSuccess($UserID) {

    header("Content-Type: application/json");
        exit(json_encode(array(

                    'UserID'    => $UserID,
                    'success'       => 'true',

        )));
    }
    function loadFailed(){

        exit(json_encode(array(

            'success'  => 'false',

        )));
    }       
?>

此代码对我不起作用..

0 个答案:

没有答案