当前位置: 首页>>代码示例>>PHP>>正文


PHP common::pdoOpen方法代码示例

本文整理汇总了PHP中common::pdoOpen方法的典型用法代码示例。如果您正苦于以下问题:PHP common::pdoOpen方法的具体用法?PHP common::pdoOpen怎么用?PHP common::pdoOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common的用法示例。


在下文中一共展示了common::pdoOpen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upgrade

function upgrade()
{
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
    $common = new common();
    $settings = new settings();
    try {
        // Add the positions.aircraft column if the portal is using MySQL or SQLite database.
        if ($settings::db_driver == "mysql") {
            // Check to see if the column already exists.
            $dbh = $common->pdoOpen();
            if (count($dbh->query("SHOW COLUMNS FROM `" . $settings::db_prefix . "positions` LIKE 'aircraft'")->fetchAll()) == 0) {
                // Add the column if it does not exist.
                $sql = "ALTER TABLE " . $settings::db_prefix . "positions ADD COLUMN aircraft BIGINT";
                $sth = $dbh->prepare($sql);
                $sth->execute();
                $sth = NULL;
            }
            $dbh = NULL;
        }
        if ($settings::db_driver == "sqlite") {
            // Check to see if the column already exists.
            $dbh = $common->pdoOpen();
            $columns = $dbh->query("pragma table_info(positions)")->fetchArray(SQLITE3_ASSOC);
            $columnExists = FALSE;
            foreach ($columns as $column) {
                if ($column['name'] == 'lastSeen') {
                    $columnExists = TRUE;
                }
            }
            // Add the column if it does not exist.
            if (!$columnExists) {
                $sql = "ALTER TABLE " . $settings::db_prefix . "positionss ADD COLUMN aircraft BIGINT";
                $sth = $dbh->prepare($sql);
                $sth->execute();
                $sth = NULL;
            }
            $dbh = NULL;
        }
        // Update the version and patch settings..
        $common->updateSetting("version", "2.1.0");
        $common->updateSetting("patch", "");
        // The upgrade process completed successfully.
        $results['success'] = TRUE;
        $results['message'] = "Upgrade to v2.1.0 successful.";
        return $results;
    } catch (Exception $e) {
        // Something went wrong during this upgrade process.
        $results['success'] = FALSE;
        $results['message'] = $e->getMessage();
        return $results;
    }
}
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:53,代码来源:upgrade-v2.1.0.php

示例2: getByPosition

function getByPosition()
{
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
    $settings = new settings();
    $common = new common();
    //
    $flightData = array();
    // PDO
    $dbh = $common->pdoOpen();
    $sql = "SELECT flight, aircraft FROM " . $settings::db_prefix . "positions WHERE id = :id";
    $sth = $dbh->prepare($sql);
    $sth->bindParam(':id', $_GET['position'], PDO::PARAM_INT);
    $sth->execute();
    $position = $sth->fetch();
    $sth = NULL;
    $dbh = NULL;
    $dbh = $common->pdoOpen();
    $sql = "SELECT flight, firstSeen, lastSeen FROM " . $settings::db_prefix . "flights WHERE id = :id";
    $sth = $dbh->prepare($sql);
    $sth->bindParam(':id', $position['flight'], PDO::PARAM_INT);
    $sth->execute();
    $flight = $sth->fetch();
    $sth = NULL;
    $dbh = NULL;
    $dbh = $common->pdoOpen();
    $sql = "SELECT icao, firstSeen, lastSeen FROM " . $settings::db_prefix . "aircraft WHERE id = :id";
    $sth = $dbh->prepare($sql);
    $sth->bindParam(':id', $position['flight'], PDO::PARAM_INT);
    $sth->execute();
    $aircraft = $sth->fetch();
    $sth = NULL;
    $dbh = NULL;
    $flightData['icao'] = $aircraft['icao'];
    $flightData['flight'] = $flight['flight'];
    $date = new DateTime($aircraft['firstSeen'], new DateTimeZone('UTC'));
    $date->setTimezone(new DateTimeZone($common->getSetting('timeZone')));
    $flightData['afs'] = $date->format($common->getSetting('dateFormat'));
    $date = new DateTime($aircraft['lastSeen'], new DateTimeZone('UTC'));
    $date->setTimezone(new DateTimeZone($common->getSetting('timeZone')));
    $flightData['als'] = $date->format($common->getSetting('dateFormat'));
    $date = new DateTime($flight['firstSeen'], new DateTimeZone('UTC'));
    $date->setTimezone(new DateTimeZone($common->getSetting('timeZone')));
    $flightData['ffs'] = $date->format($common->getSetting('dateFormat'));
    $date = new DateTime($flight['lastSeen'], new DateTimeZone('UTC'));
    $date->setTimezone(new DateTimeZone($common->getSetting('timeZone')));
    $flightData['fls'] = $date->format($common->getSetting('dateFormat'));
    return $flightData;
}
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:49,代码来源:flight.php

示例3: getVisibleFlights

function getVisibleFlights()
{
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
    $settings = new settings();
    $common = new common();
    // Get all flights to be notified about from the flightNotifications.xml file.
    $lookingFor = array();
    if ($settings::db_driver == "xml") {
        // XML
        $savedFlights = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "flightNotifications.xml");
        foreach ($savedFlights as $savedFlight) {
            $lookingFor[] = array($savedFlight);
        }
    } else {
        // PDO
        $dbh = $common->pdoOpen();
        $sql = "SELECT flight, lastMessageCount FROM " . $settings::db_prefix . "flightNotifications";
        $sth = $dbh->prepare($sql);
        $sth->execute();
        $lookingFor = $sth->fetchAll();
        $sth = NULL;
        $dbh = NULL;
    }
    // Check dump1090-mutability's aircraft JSON output to see if the flight is visible.
    $visibleFlights = array();
    $url = "http://localhost/dump1090/data/aircraft.json";
    $json = file_get_contents($url);
    $data = json_decode($json, true);
    foreach ($data['aircraft'] as $aircraft) {
        if (array_key_exists('flight', $aircraft)) {
            $visibleFlights[] = strtoupper(trim($aircraft['flight']));
        }
    }
    $foundFlights = array();
    $foundFlights['tracking'] = '';
    foreach ($lookingFor as $flight) {
        if (strpos($flight[0], "%") !== false) {
            $searchFor = str_replace("%", "", $flight[0]);
            foreach ($visibleFlights as $visible) {
                // Still needs to be modified to send data using the new format as done below.
                if (strpos(strtolower($visible), strtolower($searchFor)) !== false) {
                    $foundFlights[] = $visible;
                }
            }
        } else {
            if (in_array($flight[0], $visibleFlights)) {
                $thisFlight['flight'] = $flight[0];
                $thisFlight['lastMessageCount'] = $flight[1];
                $foundFlights['tracking'][] = $thisFlight;
            }
        }
    }
    return json_decode(json_encode((array) $foundFlights), true);
}
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:55,代码来源:notifications.php

示例4: upgrade

function upgrade()
{
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
    $common = new common();
    $settings = new settings();
    try {
        // Change tables containing datetime data to datetime.
        if ($settings::db_driver != "mysql") {
            $dbh = $common->pdoOpen();
            $sql = "ALTER TABLE " . $settings::db_prefix . "aircraft MODIFY firstSeen DATETIME NOT NULL";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $sql = "ALTER TABLE adsb_aircraft MODIFY lastSeen DATETIME NOT NULL";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $sql = "ALTER TABLE adsb_blogPosts MODIFY date DATETIME NOT NULL";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $sql = "ALTER TABLE adsb_flights MODIFY firstSeen DATETIME NOT NULL";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $sql = "ALTER TABLE adsb_flights MODIFY firstSeen DATETIME NOT NULL";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $sql = "ALTER TABLE adsb_positions MODIFY time DATETIME NOT NULL";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $dbh = NULL;
        }
        // Add timezone setting.
        $common->addSetting("timeZone", date_default_timezone_get());
        // update the version and patch settings.
        $common->updateSetting("version", "2.0.1");
        $common->updateSetting("patch", "");
        // The upgrade process completed successfully.
        $results['success'] = TRUE;
        $results['message'] = "Upgrade to v2.0.1 successful.";
        return $results;
    } catch (Exception $e) {
        // Something went wrong during this upgrade process.
        $results['success'] = FALSE;
        $results['message'] = $e->getMessage();
        return $results;
    }
}
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:52,代码来源:upgrade-v2.0.1.php

示例5: COUNT

// Items per page.
$itemsPerPage = 25;
// The title of this page.
$pageData['title'] = "Flights Seen";
// Add flight data to the $pageData array using the search string if available.
if (isset($_POST['flight'])) {
    $searchString = $_POST['flight'];
} else {
    $searchString = "";
}
// Set the start stop positions to be used in the query.
$start = 1;
if (isset($_GET['page'])) {
    $start = $_GET['page'] * $itemsPerPage;
}
$dbh = $common->pdoOpen();
$sql = "SELECT COUNT(*) FROM " . $settings::db_prefix . "flights WHERE flight LIKE :like ORDER BY lastSeen DESC, flight";
$sth = $dbh->prepare($sql);
$sth->bindValue(':like', "%" . $searchString . "%", PDO::PARAM_STR);
$sth->execute();
$totalFlights = $sth->fetchColumn();
$sth = NULL;
$dbh = NULL;
$dbh = $common->pdoOpen();
$sql = "SELECT * FROM " . $settings::db_prefix . "flights WHERE flight LIKE :like ORDER BY lastSeen DESC, flight LIMIT :start, :items";
$sth = $dbh->prepare($sql);
$sth->bindValue(':like', "%" . $searchString . "%", PDO::PARAM_STR);
$sth->bindValue(':start', $start, PDO::PARAM_INT);
$sth->bindValue(':items', $itemsPerPage, PDO::PARAM_INT);
$sth->execute();
$flights = $sth->fetchAll(PDO::FETCH_ASSOC);
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:31,代码来源:flights.php

示例6: deleteSetting

 function deleteSetting($name)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
     $settings = new settings();
     if ($settings::db_driver == "xml") {
         $xmlSettings = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "settings.xml");
         foreach ($xmlSettings as $xmlSetting) {
             if ($xmlSetting->name == $name) {
                 $dom = dom_import_simplexml($xmlSetting);
                 $dom->parentNode->removeChild($dom);
             }
         }
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "settings.xml", $xmlSettings->asXml());
     } else {
         // PDO
         require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
         $common = new common();
         $dbh = $common->pdoOpen();
         $sql = "DELETE FROM " . $settings::db_prefix . "settings WHERE name = :name";
         $sth = $dbh->prepare($sql);
         $sth->bindParam(':name', $name, PDO::PARAM_STR, 100);
         $sth->execute();
         $sth = NULL;
         $dbh = NULL;
     }
 }
开发者ID:pinkfroot,项目名称:adsb-feeder,代码行数:26,代码来源:common.class.php

示例7: getLoginUsingToken

 function getLoginUsingToken($token)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
     $settings = new settings();
     if ($settings::db_driver == "xml") {
         // XML
         $administrators = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "administrators.xml");
         foreach ($administrators as $administrator) {
             if ($administrator->token == $token) {
                 return $administrator->login;
             }
         }
         return NULL;
     } else {
         // PDO
         require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
         $common = new common();
         $dbh = $common->pdoOpen();
         $sql = "SELECT * FROM " . $settings::db_prefix . "administrators WHERE token = :token";
         $sth = $dbh->prepare($sql);
         $sth->bindParam(':token', $token, PDO::PARAM_STR, 10);
         $sth->execute();
         $row = $sth->fetch();
         $sth = NULL;
         $dbh = NULL;
         return $row['login'];
     }
 }
开发者ID:pinkfroot,项目名称:adsb-feeder,代码行数:28,代码来源:account.class.php

示例8: upgrade

function upgrade()
{
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
    require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
    $common = new common();
    $settings = new settings();
    try {
        if ($settings::db_driver == "xml") {
            // Create XML files used to store links data.
            $xml = new XMLWriter();
            $xml->openMemory();
            $xml->setIndent(true);
            $xml->startDocument('1.0', 'UTF-8');
            $xml->startElement("links");
            $xml->endElement();
            file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "links.xml", $xml->flush(true));
        }
        if ($settings::db_driver == "mysql") {
            $dbh = $common->pdoOpen();
            // Add the links table.
            $sql = "CREATE TABLE " . $settings::db_prefix . "links(id INT(11) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, address VARCHAR(250) NOT NULL);";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $dbh = NULL;
        }
        if ($settings::db_driver == "sqlite") {
            // Create a new settings.class.php file adding the path to the SQLite database as the value for the db_host constant.
            $content = <<<EOF
<?php

    /////////////////////////////////////////////////////////////////////////////////////
    //                            ADS-B RECEIVER PORTAL                                //
    // =============================================================================== //
    // Copyright and Licensing Information:                                            //
    //                                                                                 //
    // The MIT License (MIT)                                                           //
    //                                                                                 //
    // Copyright (c) 2015-2016 Joseph A. Prochazka                                     //
    //                                                                                 //
    // Permission is hereby granted, free of charge, to any person obtaining a copy    //
    // of this software and associated documentation files (the "Software"), to deal   //
    // in the Software without restriction, including without limitation the rights    //
    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell       //
    // copies of the Software, and to permit persons to whom the Software is           //
    // furnished to do so, subject to the following conditions:                        //
    //                                                                                 //
    // The above copyright notice and this permission notice shall be included in all  //
    // copies or substantial portions of the Software.                                 //
    //                                                                                 //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR      //
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,        //
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE     //
    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER          //
    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,   //
    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE   //
    // SOFTWARE.                                                                       //
    /////////////////////////////////////////////////////////////////////////////////////

    class settings {
        // Database Settings
        const db_driver = 'sqlite';
        const db_database = '';
        const db_username = '';
        const db_password = '';
        const db_host = '/var/www/html/data/portal.sqlite';
        const db_prefix = 'adsb_';

        // Security Settings
        const sec_length = 6;

        // PDO Settings
        const pdo_debug = TRUE;
    }

?>
EOF;
            file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php", $content);
            // Open a connection to the database.
            $dbh = $common->pdoOpen();
            // Add the links table.
            $sql = "CREATE TABLE " . $settings::db_prefix . "links(INTEGER PRIMARY KEY, name TEXT NOT NULL, address TEXT NOT NULL);";
            $sth = $dbh->prepare($sql);
            $sth->execute();
            $sth = NULL;
            $dbh = NULL;
        }
        // Rename the enableFlightNotifications to enableWebNotifications.
        $enableWebNotifications = $common->getSetting('enableFlightNotifications');
        $common->addSetting('enableWebNotifications', $enableWebNotifications);
        $common->deleteSetting('enableFlightNotifications');
        // Add Google Maps API Key setting.
        $common->addSetting('googleMapsApiKey', '');
        // Add enable custom links setting.
        $common->addSetting('enableLinks', FALSE);
        // Update the version and patch settings..
        $common->updateSetting("version", "2.5.0");
        $common->updateSetting("patch", "");
        // The upgrade process completed successfully.
        $results['success'] = TRUE;
//.........这里部分代码省略.........
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:101,代码来源:upgrade-v2.5.0.php

示例9: addPost

 function addPost($author, $title, $contents)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
     $settings = new settings();
     if ($settings::db_driver == "xml") {
         // XML
         $blogPosts = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "blogPosts.xml");
         $blogPost = $blogPosts->addChild('blogPost', '');
         $blogPost->addChild('title', $title);
         $blogPost->addChild('date', gmdate('Y-m-d H:i:s', time()));
         $blogPost->addChild('author', $author);
         $blogPost->addChild('contents', html_entity_decode($contents, null, "UTF-8"));
         $dom = dom_import_simplexml($blogPosts)->ownerDocument;
         $dom->formatOutput = TRUE;
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "blogPosts.xml", $dom->saveXML());
     } else {
         // PDO
         require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
         $common = new common();
         $dbh = $common->pdoOpen();
         $sql = "INSERT INTO " . $settings::db_prefix . "blogPosts (title, date, author, contents) VALUES (:title, :date, :author, :contents)";
         $sth = $dbh->prepare($sql);
         $sth->bindParam(':title', $title, PDO::PARAM_STR, 100);
         $sth->bindParam(':date', gmdate('Y-m-d H:i:s', time()), PDO::PARAM_STR, 20);
         $sth->bindParam(':author', $author, PDO::PARAM_STR, 100);
         $sth->bindParam(':contents', $contents, PDO::PARAM_STR, 20000);
         $sth->execute();
         $sth = NULL;
         $dbh = NULL;
     }
 }
开发者ID:jprochazka,项目名称:adsb-receiver,代码行数:31,代码来源:blog.class.php


注:本文中的common::pdoOpen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。