PHP PDO不向数据库发布数据

时间:2017-03-14 17:34:37

标签: php mysql curl pdo

我有一个PHP脚本设置为cURL某些URL,然后发布延迟&响应数据库的时间。然而,它并没有向数据库发布任何内容。我已经在连接和语句上完成了var_dump,并且它似乎并不像PDO将任何内容绑定到语句

var_dump of the statement = object(PDOStatement)#2 (1) { ["queryString"]=> string(91) "UPDATE `status` SET response_code=?, response_time=?, status=?, service=? WHERE `service`=?" } 

var_dump of the connection = object(PDO)#1 (0) { } 

以下是代码:

<?php
        require_once("config.php");

        if (!ini_get('display_errors')) {
            ini_set('display_errors', '1');
        }

    function CheckURL($url, $service) {
            if (!filter_var($url, FILTER_VALIDATE_URL)){
                return false;
            }

            $agent = "Mozilla/5.0 (compatible; GGStatus/1.0; +http://ggradio.net/)";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_USERAGENT, $agent);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt ($ch,CURLOPT_VERBOSE, false);
                curl_setopt($ch, CURLOPT_TIMEOUT, 5);
                curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($ch,CURLOPT_SSLVERSION, 3);
                curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
                curl_setopt($ch, CURLOPT_TIMEOUT, 5);
                $page = curl_exec($ch);
                $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                $time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
                curl_close($ch);

                try {
                        $conn = new PDO('mysql:host=127.0.0.1:3306;dbname=test;charset=utf8', 'root', 'root', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

                        $stmt = $conn->prepare("UPDATE `status` SET response_code=?, response_time=?, status=?, service=? WHERE `service`=?");

                        if($httpcode == 200){
                            $status = "Operational"; //green
                        } elseif ($time > 5) {
                            $status = "Delayed"; //orange-yellow
                        } else {
                            $status = "Down"; //red
                        }

                        $stmt->bindValue(1, $httpcode, PDO::PARAM_STR);
                        $stmt->bindValue(2, $time, PDO::PARAM_STR);
                        $stmt->bindValue(3, $status, PDO::PARAM_STR);
                        $stmt->bindValue(4, $service, PDO::PARAM_STR);
                        $stmt->bindValue(5, $service, PDO::PARAM_STR);
                        $stmt->execute();
                } 
                catch(PDOException $e){
                        echo $e->getMessage();
                }
    }

        function urlName($url){
                $name = "";

                switch($url){
                        case "http://ggradio.net/":
                            $name = "Site";break;
                        case "http://ggradio.net/community/":
                            $name = "Forums";break;
                        case "http://sv.ggradio.net:8000/":
                            $name = "Radio";break;
                        case "http://api.ggradio.net/php/song/":
                            $name = "API";break;
                        case "http://cdn.ggradio.net/":
                            $name = "CDN";break;
                        case "http://panel.ggrad.io/":
                            $name = "Panel";break;
                        default:
                            $name = "None provided";break;
                }
                return $name;
        }

        foreach($urlsToPing as $url){
                CheckURL($url, urlName($url));
        }

?>

0 个答案:

没有答案