Web服务数据库连接

时间:2016-03-16 08:04:58

标签: php mysql web-services

我在具有mysql数据库连接的服务器上开发了一个php web服务。它无法连接到数据库,并且在数据库连接后不执行代码。它也没有显示任何错误。 如果我在数据库连接行之前返回一些内容,则返回它。 我已经测试了另一个带有数据库连接的php文件,它可以正常工作。

    <?php require_once('lib/nusoap.php'); 

   $server = new soap_server();

   $server->configureWSDL('ivrmci', 'urn:ivrmciwsdl');


    $server->register('upload_file',                                 // method
        array('username' => 'xsd:string','password' => 'xsd:string','encoded_filepath' => 'xsd:string','filename' => 'xsd:string'),    // input parameters
        array('return' => 'xsd:string'),                             // output parameters
        'urn:ivrmciwsdl',                                            // namespace
        'urn:ivrmciwsdl#upload_file',                                // soapaction
        'rpc',                                                       // style
        'encoded',                                                   // use
        'Uploads files to the server'                                // documentation
    );

       $server->register('inquiryMsisdnCalls',                                 // method
        array('username' => 'xsd:string','password' => 'xsd:string','callerid' => 'xsd:string','advertise_id' => 'xsd:string'),    // input parameters
        array('return' => 'xsd:string'),                             // output parameters
        'urn:ivrmci',                                            // namespace
        'urn:ivrmci#inquiryMsisdnCalls',                                // soapaction
        'rpc',     
        'encoded',                                                  // style                                                   // use
        'Returns User Log'                                // documentation
    );

    function upload_file($username,$password,$encoded,$name) {


        if ($username != "abc" OR $password != "123") 
        {
             return "-2";
        }


        $location = "uploads/".$name;                               // Mention where to upload the file
        //$current = file_get_contents($location);                     // Get the file content. This will create an empty file if the file does not exist     
        $current = base64_decode($encoded);                          // Now decode the content which was sent by the client     
        file_put_contents($location, $current);                      // Write the decoded content in the file mentioned at particular location      

        try
        {
            $db = new PDO('mysql:dbname=zzz;host=x.x.x.x',"root","1234",array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        }

        catch(PDOException $e)
        {
            return "-3";
        }


        $filename = explode(".", $name);
        $sql    = "INSERT INTO advertise (name) VALUES ($filename[0])";
        try{

            $db->exec($sql);
            return $db->lastInsertid();

        }
        catch(PDOException $e)
        {
            return $e->getMessage();
        }
        if($name!="")
        {

            return "File Uploaded successfully...";                      // Output success message                              
        }
        else        
        {
            return "Please upload a file...";
        }
    }


    function inquiryMsisdnCalls($username,$password,$callerid,$contentid)
    {


        if ($username != "abc" OR $password != "123") 
        {
             return "-2";
        }
        try
        {
            $db = new PDO('mysql:dbname=zzz;host=x.x.x.x',"root","1234",array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        }

        catch(PDOException $e)
        {
            return "-3";
        }


        $sql    = "select status from user_advertise_log where callerId=$callerid and advertise_id=$contentid";
        try{

            $log = $db->query($sql)->fetch(PDO::FETCH_OBJ);
            return $log->status;

        }
        catch(PDOException $e)
        {
            return $e->getMessage();
        }
    }



    // Use the request to (try to) invoke the service
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA); 
?>

0 个答案:

没有答案