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


PHP Database::obtain方法代码示例

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


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

示例1: doAction

 public function doAction()
 {
     switch ($this->__postInput['exec']) {
         case 'stayAnonymous':
             unset($_SESSION['_anonym_pid']);
             unset($_SESSION['incomingUrl']);
             unset($_SESSION['_newProject']);
             break;
         case 'ping':
             $db = Database::obtain();
             $db->query("SELECT 1");
             $this->result['data'] = array("OK", time());
             break;
         case 'checkTMKey':
             //get MyMemory apiKey service
             $tmxHandler = new TMSService();
             $tmxHandler->setTmKey($this->__postInput['tm_key']);
             //validate the key
             try {
                 $keyExists = $tmxHandler->checkCorrectKey();
             } catch (Exception $e) {
                 /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */
                 Log::doLog($e->getMessage());
             }
             if (!isset($keyExists) || $keyExists === false) {
                 $this->result['errors'][] = array("code" => -9, "message" => "TM key is not valid.");
                 Log::doLog(__METHOD__ . " -> TM key is not valid.");
                 $this->result['success'] = false;
             } else {
                 $this->result['errors'] = array();
                 $this->result['success'] = true;
             }
             break;
     }
 }
开发者ID:kevinvnloctra,项目名称:MateCat,代码行数:35,代码来源:ajaxUtilsController.php

示例2: showPost

 function showPost($id)
 {
     $db = Database::obtain();
     $sql = "SELECT " . tbl_blog . ".id, title, content, date_posted, username \n                        FROM " . tbl_blog . "\n                        JOIN " . tbl_users . " \n                        ON " . tbl_blog . ".user_id = " . tbl_users . ".id\n                \tWHERE " . tbl_blog . ".id = " . (int) $id;
     $rows = $db->fetch_array($sql);
     return $rows;
 }
开发者ID:vebnz,项目名称:lifelitup,代码行数:7,代码来源:blog.php

示例3: testReturnsNonCompletedProject

 function testReturnsNonCompletedProject()
 {
     $this->setValidProjectWithAllTranslatedSegments();
     // get project chunks
     $chunksDao = new Chunks_ChunkDao(Database::obtain());
     $chunks = $chunksDao->getByProjectID($this->test_data->project->id_project);
     $this->assertEquals(1, count($chunks));
     $chunk = $chunks[0];
     // split job in two
     $splitTest = new CurlTest();
     $params = array('action' => 'splitJob', 'exec' => 'apply', 'project_id' => $this->test_data->project->id_project, 'project_pass' => $this->test_data->project->project_pass, 'job_id' => $chunk->id, 'job_pass' => $chunk->password, 'num_split' => 2, 'split_values' => array('5', '1'));
     $splitTest->params = $params;
     $splitTest->method = 'POST';
     $response = $splitTest->getResponse();
     $chunks = $chunksDao->getByProjectID($this->test_data->project->id_project);
     $this->assertEquals(2, count($chunks));
     $first_chunk = $chunks[0];
     $second_chunk = $chunks[1];
     integrationSetChunkAsComplete(array('params' => array('id_job' => $first_chunk->id, 'password' => $first_chunk->password)));
     $test = new CurlTest();
     $test->path = '/api/v2/project-completion-status/' . $this->test_data->project->id_project;
     $test->method = 'GET';
     $test->headers = $this->test_data->headers;
     $response = $test->getResponse();
     $expected = array('project_status' => array('id' => $this->test_data->project->id_project, 'completed' => false, 'chunks' => array(array('id' => $second_chunk->id, 'password' => $second_chunk->password))));
     $this->assertEquals(json_encode($expected), $response['body']);
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:27,代码来源:ProjectCompletionStatusTest.php

示例4: __construct

 /**
  * Create a new FileFormatConverter, using old or new converters.
  * This function looks for converters in the 'converters' table in the db.
  * $converterVersion can be "legacy", "latest", or something like "1.0.0".
  * In the first case legacy converters will be used; in the second case,
  * the latest version of new converters will be used; in the third case,
  * this function will look for the converters with the provided version,
  * and if not found will use the converters with higher but closest version.
  * Version check is done on the conversion_api_version field of the
  * converters db table; new converters are expected to have a value like
  * "open 1.0.0".
  */
 public function __construct($converterVersion = null)
 {
     $this->converterVersion = $converterVersion;
     $this->opt['httpheader'] = array("Content-Type:multipart/form-data;charset=UTF-8");
     $this->lang_handler = Langs_Languages::getInstance();
     $this->conversionObject = new ArrayObject(array('ip_machine' => null, 'ip_client' => null, 'path_name' => null, 'file_name' => null, 'path_backup' => null, 'file_size' => 0, 'direction' => null, 'error_message' => null, 'src_lang' => null, 'trg_lang' => null, 'status' => 'ok', 'conversion_time' => 0), ArrayObject::ARRAY_AS_PROPS);
     // Get converters instances list from database,
     $db = Database::obtain();
     // The base query to obtain the converters
     $baseQuery = 'SELECT ip_converter, cpu_weight, ip_storage, segmentation_rule' . ' FROM converters' . ' WHERE status_active = 1 AND status_offline = 0';
     // Complete the $baseQuery according to the converter's version
     if ($this->converterVersion == Constants_ConvertersVersions::LEGACY) {
         // Retrieve only old converters
         $query = $baseQuery . (INIT::$USE_ONLY_STABLE_CONVERTERS ? ' AND stable = 1' : '') . ' AND conversion_api_version NOT LIKE "open %"';
         $converters = $db->fetch_array($query);
     } else {
         // Here we use new converters
         if ($this->converterVersion == Constants_ConvertersVersions::LATEST) {
             // Get the converters with the latest version
             $query = $baseQuery . ' AND conversion_api_version = (' . 'SELECT MAX(conversion_api_version)' . ' FROM converters' . ' WHERE conversion_api_version LIKE "open %"' . (INIT::$USE_ONLY_STABLE_CONVERTERS ? ' AND stable = 1' : '') . ' AND status_active = 1 AND status_offline = 0' . ')';
             $converters = $db->fetch_array($query);
         } else {
             $converters = self::__getSuitableConvertersByVersion($db, $this->converterVersion);
         }
     }
     foreach ($converters as $converter_storage) {
         $this->converters[$converter_storage['ip_converter']] = $converter_storage['cpu_weight'];
         $this->storage_lookup_map[$converter_storage['ip_converter']] = $converter_storage['ip_storage'];
         $this->converter2segmRule[$converter_storage['ip_converter']] = $converter_storage['segmentation_rule'];
     }
     //        $this->converters = array('10.30.1.32' => 1);//for debugging purposes
     //        $this->storage_lookup_map = array('10.30.1.32' => '10.30.1.32');//for debugging purposes
 }
开发者ID:bcrazvan,项目名称:MateCat,代码行数:45,代码来源:FileFormatConverter.php

示例5: __construct

 public function __construct()
 {
     $this->ROOT = realpath(dirname(__FILE__) . '/../../../');
     //imports
     require_once $this->ROOT . '/inc/config.inc.php';
     Bootstrap::start();
     $this->db = Database::obtain(INIT::$DB_SERVER, INIT::$DB_USER, INIT::$DB_PASS, INIT::$DB_DATABASE);
     $this->db->connect();
     //init params
     $this->path = $this->ROOT . '/lib/Utils/converter_checker';
     $resultSet = $this->db->fetch_array(self::selectAllNotOffline);
     if (empty($resultSet)) {
         self::_prettyEcho("------------------------------------");
         self::_prettyEcho("************* WARNING **************");
         self::_prettyEcho("------------------------------------");
         $this->alertForEmptyPool();
         die(1);
     }
     foreach ($resultSet as $conv) {
         //            self::$ipLog = $conv[ 'ip_converter' ];
         $this->resultSet[$conv['ip_converter']] = $conv;
         $this->host_machine_map[$conv['ip_converter']] = array('ip_machine_host' => $conv['ip_machine_host'], 'machine_host_user' => $conv['machine_host_user'], 'machine_host_pass' => $conv['machine_host_pass'], 'instance_name' => $conv['instance_name']);
         //            self::_prettyEcho( "Retrieving Processes Info on " . $conv[ 'ip_converter' ] );
         //            $converter_json_top = self::getNodeProcessInfo( $conv[ 'ip_converter' ] );
         //            if ( !empty( $converter_json_top ) ) {
         //                $this->convertersTop[ $conv[ 'ip_converter' ] ] = array(
         //                    'converter_load'     => $converter_json_top[ 0 ],
         //                    'converter_json_top' => $converter_json_top[ 1 ]
         //                );
         //            }
     }
     $this->converterFactory = new FileFormatConverter();
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:33,代码来源:check_converter_by_file_content.php

示例6: addFriend

function addFriend($id, $target)
{
    $db = Database::obtain();
    $sql = 'SELECT friends FROM users WHERE id = ' . $db->escape($id);
    $query = $db->query($sql);
    $result = $db->fetch($query);
    $friends = $result['friends'];
    $fids = explode(",", $friends);
    foreach ($fids as $fid) {
        if ($fid == $target) {
            $true = 1;
        }
    }
    if ($true != 1) {
        if ($target == $id) {
            echo "You can't friend yourself.";
        } else {
            if ($friends == "") {
                $friends .= $target;
            } else {
                $friends .= ',' . $target;
            }
            $data['friends'] = $friends;
            $where = 'id = ' . $db->escape($id);
            $sql = $db->update('users', $data, $where);
            echo 'Friend added.';
        }
    } else {
        echo 'You already friend with this player.';
    }
}
开发者ID:marat1803,项目名称:tf2matchmaking,代码行数:31,代码来源:friends.php

示例7: uncompletedChunksByProjectId

 static function uncompletedChunksByProjectId($id_project)
 {
     // for each project you can have several jobs, one per targert language.
     // for each job you can have one or more chunks.
     // jobs are identified by id_job and target language.
     // chunks are identified by id_job and password.
     //
     // translations have a reference to job, not to the chunk.
     // in order to associate the segment_translation to the chunk we need to
     // refer to the start and stop segment stored on the job.
     //
     // I would be great if we could have a chunk identifier on the segment_translation.
     // segments don't have a reference to the job neither, since they are linked to the file.
     //
     $query_most_recent_completion_events_for_chunk = " " . " SELECT * FROM ( " . " SELECT * FROM chunk_completion_events WHERE id_project = :id_project " . " ORDER BY create_date DESC ) t " . " GROUP BY id_project, id_job, password ";
     // This query should return no records, meaning all submitted events have
     // create_date greater than the chunk's latest translation date.
     $query_for_event_submitted_at_least_once = "SELECT ch.id_job, ch.password " . " FROM segment_translations st INNER JOIN " . "( {$query_most_recent_completion_events_for_chunk} ) ch ON " . " st.id_segment BETWEEN ch.job_first_segment AND ch.job_last_segment " . " AND st.id_job = ch.id_job AND ch.id_project = :id_project " . " AND ch.create_date < st.translation_date";
     // This query should return no records, meaning all jobs have at least one
     // submitted chunk completion event.
     $query_to_return_unsubmitted_chunks = "SELECT jobs.id as id_job, jobs.password " . " FROM jobs LEFT JOIN chunk_completion_events ch ON " . " jobs.id = ch.id_job AND " . " jobs.password = ch.password AND " . " jobs.job_first_segment = ch.job_first_segment AND " . " jobs.job_last_segment = ch.job_last_segment AND " . " jobs.id_project = ch.id_project " . " WHERE jobs.id_project = :id_project " . " AND ch.id IS NULL ";
     $union_query = "SELECT * FROM ( {$query_to_return_unsubmitted_chunks} " . " UNION ALL {$query_for_event_submitted_at_least_once} ) t1 " . " GROUP BY id_job, password ";
     $query_to_return_chunks = "SELECT * from jobs INNER JOIN ( {$union_query} ) filtered " . " ON jobs.id = filtered.id_job AND jobs.password = filtered.password ";
     $conn = Database::obtain()->getConnection();
     Log::doLog($query_to_return_chunks);
     $stmt = $conn->prepare($query_to_return_chunks);
     $stmt->execute(array('id_project' => $id_project));
     $stmt->setFetchMode(PDO::FETCH_CLASS, 'Chunks_ChunkStruct');
     return $stmt->fetchAll();
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:30,代码来源:ProjectDao.php

示例8: create

 static function create($values)
 {
     $values = array_merge(array('uid' => 1, 'feature_code' => 'project_completion', 'options' => '{}', 'enabled' => true), $values);
     $dao = new OwnerFeatures_OwnerFeatureDao(Database::obtain());
     $struct = new OwnerFeatures_OwnerFeatureStruct($values);
     return $dao->create($struct);
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:7,代码来源:OwnerFeature.php

示例9: post

 function post($request)
 {
     $response = new Response($request);
     if (isset($_POST['exception'])) {
         $db = Database::obtain();
         $exception = $_POST['exception'];
         $query_obj = array();
         $sql = "SELECT * FROM `" . TABLE_ERRORS . "` WHERE `exception`='" . $exception . "'";
         $row = $db->query_first($sql);
         if (empty($row['id'])) {
             $query_obj['exception'] = $_POST['exception'];
             $query_obj['appearance'] = 0;
         } else {
             $query_obj['exception'] = $row['exception'];
             $query_obj['first_submit'] = $row['first_submit'];
             $query_obj['appearance'] = $row['appearance'];
             if (!empty($row['solution'])) {
                 $query_obj['solution'] = $row['solution'];
             }
         }
         $response->code = Response::OK;
         $response->addHeader('Content-type', 'text/plain');
         $response->body = json_encode($query_obj);
     } else {
         $response->code = Response::BADREQUEST;
     }
     return $response;
 }
开发者ID:ThomDietrich,项目名称:gctour,代码行数:28,代码来源:errors_query.php

示例10: showTemplates

function showTemplates($start_record, $end_record, $category_id = NULL)
{
    $db = Database::obtain();
    if ($category_id == NULL) {
        $filter = '';
    } else {
        $filter = 'WHERE `template_category` = ' . $db->escape($category_id);
    }
    $sql = "SELECT * FROM `" . TABLE_TEMPLATES . "`\n\t\t\t\t" . $filter . "\n\t\t\t\tORDER BY name ASC\n\t\t\t\tLIMIT " . $start_record . "," . $end_record . "";
    $templates = $db->fetch_array($sql);
    $templateList = array();
    foreach ($templates as $template) {
        $templateList[] = $template['name'];
        if ($template['id'] == $website_template) {
            $website_template = $template['name'];
        }
    }
    $form = '<table cellspacing="10" border="0" align="center"><tr>';
    foreach ($templateList as $i => $t) {
        $form .= '<td align="center">';
        if ($t == $website_template) {
            $form .= $t . '<br><img src="templates/' . $t . '/preview.jpg" width="150px" height="100px"><br>' . MSG00092 . ' <input name="website_template" value="' . $t . '" type="radio"  checked="checked" /><br/>';
        } else {
            $form .= $t . '<br><img src="templates/' . $t . '/preview.jpg" width="150px" height="100px"><br>' . MSG00092 . ' <input name="website_template" value="' . $t . '" type="radio" /><br />';
        }
        $form .= '</td>';
        if (($i + 1) % 4 == 0) {
            $form .= '<tr></tr>';
        }
    }
    $form .= '</tr></table>';
    $form .= linkButton(scriptName() . '?website&edit=' . $website_id . '&settings', MSG00089);
    echo $form;
}
开发者ID:hscale,项目名称:SiteZilla,代码行数:34,代码来源:templates.php

示例11: getAllUsers

 function getAllUsers()
 {
     $db = Database::obtain();
     $sql = "SELECT *\n\t\t\tFROM " . tbl_users;
     $rows = $db->fetch_array($sql);
     return $rows;
 }
开发者ID:vebnz,项目名称:lifelitup,代码行数:7,代码来源:user.php

示例12: login

 public function login($username, $password)
 {
     $username = htmlentities($username);
     $password = md5($password);
     if (User::user_exists($username)) {
         $db = Database::obtain();
         $sql = "SELECT `id`,`username`,`password` FROM " . TABLE_USERS . "\n\t\t\t\t\tWHERE `username` = '" . $db->escape($username) . "'";
         $userdata = $db->query_first($sql);
         if ($username == $userdata['username'] && $password == $userdata['password']) {
             $_SESSION['userkey'] = md5($_SERVER["REMOTE_ADDR"] . $_SERVER["HTTP_USER_AGENT"] . md5($userdata['password']));
             $_SESSION['userid'] = $userdata['id'];
             // Check if Javascript is enable from hidden value in <noscript></noscript> in the login form
             $js_disabled = 0;
             $_SESSION['js_disabled'] = 0;
             if (isset($_POST['js_disabled'])) {
                 $js_disabled = $_POST['js_disabled'];
             }
             if ($js_disabled == 1) {
                 $_SESSION['js_disabled'] = 1;
             }
             $this->userid = $userdata['id'];
             $this->logged_in = true;
             return true;
         }
     } else {
         return false;
     }
 }
开发者ID:hscale,项目名称:SiteZilla,代码行数:28,代码来源:session.php

示例13: getAggregatedBySegmentIdInInterval

 /**
  * @param $start start segment
  * @param $stop stop segment
  * @return array array aggregated by id_segment
  */
 public static function getAggregatedBySegmentIdInInterval($start, $stop)
 {
     $conn = Database::obtain()->getConnection();
     $stmt = $conn->prepare("SELECT id_segment, id, note FROM segment_notes " . " WHERE id_segment BETWEEN :start AND :stop ");
     $stmt->execute(array('start' => $start, 'stop' => $stop));
     return $stmt->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_ASSOC);
 }
开发者ID:indynagpal,项目名称:MateCat,代码行数:12,代码来源:SegmentNoteDao.php

示例14: saveWebsiteSettings

function saveWebsiteSettings($website)
{
    $db = Database::obtain();
    $id = $website['id'];
    $db->update(TABLE_WEBSITES, $website, "id='" . $id . "'");
    sysMsg(MSG00003);
}
开发者ID:hscale,项目名称:SiteZilla,代码行数:7,代码来源:settings_functions.php

示例15: createNavbar

 function createNavbar($logged_in)
 {
     $db = Database::obtain();
     $sql = "SELECT id, name, url\n\t\t\tFROM " . tbl_pages . "\n\t\t\tWHERE logged_in = " . (int) $logged_in;
     $row = $db->fetch_array($sql);
     return $row;
 }
开发者ID:vebnz,项目名称:lifelitup,代码行数:7,代码来源:pages.php


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