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


PHP connect_to_db函数代码示例

本文整理汇总了PHP中connect_to_db函数的典型用法代码示例。如果您正苦于以下问题:PHP connect_to_db函数的具体用法?PHP connect_to_db怎么用?PHP connect_to_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: define

<?php

define('SUCCESS', 0);
define('FILE_NOT_FOUND', 1);
define('DATABASE_NOT_EXISTS', 2);
define('ERR', [FILE_NOT_FOUND => 'config file not found, run install.php', DATABASE_NOT_EXISTS => 'database not eists. create new database.']);
function connect_to_db($config_file) : int
{
    if (!file_exists($config_file)) {
        return FILE_NOT_FOUND;
    }
    return SUCCESS;
}
$is_connect = connect_to_db('/etc/php7test.ini');
if ($is_connect != SUCCESS) {
    echo ERR[$is_connect];
}
开发者ID:seifzadeh,项目名称:php7-sample,代码行数:17,代码来源:constant_array.php

示例2: _start

function _start()
{
    global $db_con, $d_user, $d_pw, $d_base, $d_server, $d_pre;
    include_once 'config.php';
    $db_con = connect_to_db($d_user, $d_pw, $d_base, $d_server);
    define('DB_PREFIX', $d_pre);
}
开发者ID:BackupTheBerlios,项目名称:comacms-svn,代码行数:7,代码来源:functions.php

示例3: get_book_number

function get_book_number()
{
    $conn = connect_to_db();
    $book_num = -1;
    $book_num_row = $conn->query('SELECT COUNT(*) FROM hahhtable');
    $book_num = $book_num_row->fetch_row()[0];
    $conn->close();
    return $book_num;
}
开发者ID:subsevenx2001,项目名称:HathHelper,代码行数:9,代码来源:lib.php

示例4: model_location_and_time_array

function model_location_and_time_array($latitude, $longitude, $radius, $datetime, $numresults, $pollutant, $maxfit)
{
    $query = query_location_time_circle_unique_entries($latitude, $longitude, $radius, $datetime, $pollutant);
    $dbresult = connect_to_db($query);
    $rows = mysql_num_rows($dbresult);
    $array = generate_array($dbresult);
    $array = array_strip($array, $pollutant, $numresults, $maxfit);
    return $array;
}
开发者ID:unswjasonhu,项目名称:airpollution_modeling,代码行数:9,代码来源:oldmodel.php

示例5: get_smallbiz_tax_rate

function get_smallbiz_tax_rate($gross_income)
{
    if ($GLOBALS['$connected'] == False) {
        connect_to_db();
    }
    $sql = "SELECT tax_rate, income FROM smallbiz_brackets";
    $result = mysql_query($sql);
    while ($row = @mysql_fetch_array($result)) {
        $low = $row["income_low"];
        $high = $row["income_high"];
        if ($low <= $total_income && $high >= $total_income) {
            return $row["tax_rate"];
        }
    }
}
开发者ID:patthickey,项目名称:software_engineering,代码行数:15,代码来源:test_corp_tax.php

示例6: sync_products

function sync_products($vid = NULL, $cid = NULL)
{
    global $conn;
    connect_to_db();
    $sql = "\nSELECT c.channel_id, c.channel, c.products_api, s.store_id, s.store_name, s.api_key, s.api_password, s.access_token, v.vendor\n  FROM store AS s\n  JOIN vendor AS v ON s.vendor_id = v.vendor_id\n  JOIN channel AS c ON s.channel_id = c.channel_id\n  WHERE 1\n";
    if ($vid && preg_match('/^\\d+$/', $vid)) {
        $sql .= ' AND s.vendor_id=' . $vid;
    }
    if ($cid && preg_match('/^\\d+$/', $cid)) {
        $sql .= ' AND s.channel_id=' . $cid;
    }
    // actually, Vend's API can be accessed using a private access-token without expiration!
    $query = mysqli_query($conn, $sql);
    while ($row = mysqli_fetch_assoc($query)) {
        extract($row);
        $api_url = str_replace(['{STORE_NAME}', '{API_KEY}', '{API_PASSWORD}', '{ACCESS_TOKEN}'], [$store_name, $api_key, $api_password, $access_token], $products_api);
        $store = new stdClass();
        $store->store_name = $store_name;
        $store->vendor = $vendor;
        $store->channel = $channel;
        $store->api_url = $api_url;
        $stores[$store_id] = $store;
    }
    $stores_apis = array_combine(array_keys($stores), array_map(function ($x) {
        return $x->api_url;
    }, $stores));
    $api_results = fetch_products($stores_apis);
    $results = [];
    foreach ($stores as $store_id => $store) {
        $result = new stdClass();
        $result->store_name = $store->store_name;
        $result->vendor = $store->vendor;
        $result->channel = $store->channel;
        if (!empty($api_results[$store_id])) {
            $channel_products = json_decode($api_results[$store_id]);
            $products = translate_channel_products($store->channel, $channel_products);
            save_products($store_id, $products);
            $result->status = 'succeeded';
        } else {
            $result->status = 'failed';
        }
        $results[$store_id] = $result;
    }
    return $results;
}
开发者ID:charlesqwu,项目名称:lite,代码行数:45,代码来源:Lite.php

示例7: displayform

function displayform($currentstudent = "")
{
    $dbc = connect_to_db("jed");
    $query = "select ID, lastname, firstname from student";
    $result = perform_query($dbc, $query);
    echo "<form method=\"get\">\n\t\t  <select name=\"studentmenu\">";
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $firstname = $row['firstname'];
        $lastname = $row['lastname'];
        $id = $row['ID'];
        if ($id == $currentstudent) {
            echo "<option value=\"{$id}\" selected>{$firstname} {$lastname}</option>\n";
        } else {
            echo "<option value=\"{$id}\">{$firstname} {$lastname}</option>\n";
        }
    }
    echo "</select>\n\t\t<input type=\"submit\" name=\"formsubmitted\" value=\"go\" />\n\t\t</form>";
    disconnect_from_db($dbc, $result);
}
开发者ID:lowriek,项目名称:CSCI1154_Examples,代码行数:19,代码来源:inclass.php

示例8: create_select

function create_select($menuname)
{
    echo "<select name= '{$menuname}'>\n";
    $dbc = connect_to_db("jed");
    $query = "select ID, lastname, firstname from student";
    $result = perform_query($dbc, $query);
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        $firstname = $row['firstname'];
        $lastname = $row['lastname'];
        $id = $row['ID'];
        if (isset($_GET[$menuname]) && $_GET[$menuname] == $id) {
            echo "<option value = '{$id}' selected> {$firstname}  {$lastname} </option>\n";
        } else {
            echo "<option value = '{$id}'> {$firstname}  {$lastname} </option>\n";
        }
    }
    echo "</select>";
    disconnect_from_db($dbc, $result);
}
开发者ID:lowriek,项目名称:CSCI1154_Examples,代码行数:19,代码来源:create_select.php

示例9: get_database_data

function get_database_data($date)
{
    global $query;
    $array = array();
    # poor-mans parameter substitution
    $new_query = str_replace("?1", $date, $query);
    $connection = connect_to_db();
    $statement = mysql_query($new_query, $connection) or die('Could not execute query\\n' . mysql_error());
    while ($row = mysql_fetch_array($statement, MYSQL_ASSOC)) {
        $id = $row["id"];
        $level = $row["content"];
        $levelgen = $row["levelgen"];
        $levelgen_filename = $row["levelgen_filename"];
        $level_filename = $row["level_filename"];
        $modified_date = $row["last_updated"];
        $new_row_array = array('id' => $id, 'level_content' => $level, 'level_filename' => $level_filename, 'levelgen_content' => $levelgen, 'levelgen_filename' => $levelgen_filename, 'modified_date' => $modified_date);
        array_push($array, $new_row_array);
    }
    mysql_close($connection);
    return $array;
}
开发者ID:AnsonX10,项目名称:bitfighter.tools,代码行数:21,代码来源:pleiades_export.php

示例10: insert_mcviz_results

/**
 *
 *
 * @param unknown $content
 * @return unknown
 */
function insert_mcviz_results($content)
{
    $replace_tag = "mcvizresults";
    if (!preg_match("/mcvizresults/", $content)) {
        return $content;
    }
    $viz_link_comment_javascript = '<div style="text-align:center"><input type="submit" value="Insert Visualization Link into Comment Box Below" onclick="document.forms.commentform.comment.value+=\'[REPLACE THIS WITH YOUR COMMENTS ABOUT THE VISUALIZATION]\\n<a href=\' + document.location + \'>My Visualization</a>\';" /></div>';
    if ($_REQUEST["viz_type"] == "pivot") {
        if ($_REQUEST["media_id"][1] == "") {
            return output_error("You did not enter a media source to chart.\n");
        }
        if (preg_match("/^\\s*\$/", $_REQUEST["pivotterm"])) {
            return output_error("You did not enter a term on which to pivot.\n");
        }
        $dbconn = connect_to_db(&$dberror);
        if ($dberror != '') {
            return output_db_error($dberror);
        }
        $tagcounts = array();
        $medianum = 0;
        foreach ($_REQUEST["media_id"] as $cur_media_id) {
            if ($cur_media_id == '') {
                continue;
            }
            $query = '';
            $result = '';
            $data = '';
            $tags = '';
            $title = '';
            $max_tag_count = '';
            $line = '';
            $pivotterm = strtolower($_REQUEST["pivotterm"]);
            $pivtotterm = preg_replace("/[^a-zA-Z0-9s]/", "", $pivotterm);
            $sub_result = pg_query_params("SELECT * FROM tag_lookup where word = \$1 ", array($pivotterm));
            if (pg_num_rows($sub_result) == 0) {
                pg_query_params("insert into tag_lookup(word, tag_sets_id, tags_id) select \$1, \$2, tags_id from tags where tag_sets_id = \$2 and (tag = \$1 or split_part(tag, ' ', 1) = \$1 or split_part(tag, ' ', 2) = \$1 or split_part(tag, ' ', 3) = \$1) order by tags_id limit 20;", array($pivotterm, $_REQUEST["tagset"]));
            }
            // or split_part(t.tag, ' ', 1) = '$pivotterm' or split_part(t.tag, ' ', 2) = '$pivotterm' or split_part(t.tag, ' ', 3) = '$pivotterm'
            $query = "select max(c.tag_count) as max_tag_count, m.name, tt.tag from media_tag_tag_counts c, tag_lookup t, tags tt, media m " . "where c.tag_tags_id = tt.tags_id and (t.word = '{$pivotterm}' ) " . "and c.tags_id = t.tags_id and c.media_id = '{$cur_media_id}' and m.media_id = c.media_id and " . "t.tag_sets_id = " . $_REQUEST["tagset"] . " and " . "tt.tag_sets_id = " . $_REQUEST["tagset"] . "group by tt.tags_id, m.name, tt.tag order by max_tag_count desc limit 10";
            //$chart .= "$query<br/>";
            $result = pg_query($query) or $dberror .= 'Query failed: ' . pg_last_error();
            if ($dberror != '') {
                return output_db_error($dberror);
            }
            while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
                /* foreach ($line as $col_value) {
                			$chart .= " | $col_value";
                    	}
                    		$chart .= "<br/>";*/
                // TODO: Fix this hack, which gives weird results unless max count is first (but in our case should always be true)
                $max_tag_count = max($max_tag_count, $line[max_tag_count]);
                $data .= round($line["max_tag_count"] / $max_tag_count * 100) . ",";
                $shorttag = $line["tag"];
                if (strlen($shorttag) > 13) {
                    $shorttag = substr($shorttag, 0, 13) . "...";
                }
                $tags = $shorttag . "|" . $tags;
                // TODO: Don't do this on every loop, instead do separate query?
                $title = $line["name"];
                if (strlen($title) > 23) {
                    $title = substr($title, 0, 23) . "...";
                }
                $tagcounts[$line["tag"]][$medianum] = $line["max_tag_count"];
            }
            $medianum++;
            //remove trailing comma - I should probably switch it to join() above
            $data = substr($data, 0, -1);
            if ($max_tag_count == '' || $max_tag_count == 0) {
                $chart .= "<br />(<b>No results for source {$medianum}.</b>  The available terms that you can currently serach for are focused on prominent people, places, and events.  This will broaden considerably in the future.)<br />";
            } else {
                $chart .= "<img src=\"http://chart.apis.google.com/chart?&cht=bhs&chs=200x300&chd=t:{$data}&chxt=y&chxl=0:|{$tags}&chtt={$title}&chxs=0,,9&chts=000000,11\" />";
            }
            // while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
            //foreach ($line as $col_value) {
            // //$media_name = $
            // $chart .= " | $col_value";
            //}
            // $chart .= "<br/>";
            //}
            //$chart .= "<br/><br/>";
        }
        // sum for each tag, find max
        // print with scaling
        //Print_r ($tagcounts);
    } elseif ($_REQUEST["viz_type"] == "top10") {
        //$chart .= "<br>top10<br>";
        if ($_REQUEST["media_id"][1] == "") {
            return $content;
        }
        foreach ($_REQUEST["media_id"] as $cur_media_id) {
            if ($cur_media_id == '') {
                continue;
            }
            $dbconn = connect_to_db(&$dberror);
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:mediacloud,代码行数:101,代码来源:mcviz.php

示例11: updateScheduleRun

function updateScheduleRun($schedule)
{
    // Use these global variables
    global $link, $finalResult, $dbResult;
    // Get a connection to the report_generator.
    $result = connect_to_db();
    if (!isset($schedule) || $schedule == '') {
        $rptuser = 1;
    }
    $query = "UPDATE tblSchedules SET nLastrun = NOW() WHERE nSchedID in ({$schedule}) ";
    $dbResult = mysqli_query($link, $query);
}
开发者ID:arvindt,项目名称:rgen,代码行数:12,代码来源:db_funcs.php

示例12: document_header

<?php

include 'functions.php';
$GLOBALS['graphid'] = 0;
// Load libraries
document_header();
// Create connection
$link = connect_to_db();
?>
	<div id="data" style="display: none">
	
	<h2>Data</h2>
	
	<p>In this section we carry out an initial analysis of past transactions, with the objective of gathering information about the categories, products and customers that tend to generate the highest revenues. The results shown in this page can provide insights to inform the activities of the sales team. This information, together with the recommendation system and customer analysis which we have implemented in the next page, can support the activities of the company's marketing team.</p>
	
	<p> The chart below shows the best selling products ranked according to the revenues they generate. Only the top 10 best selling products are shown.</p>

<?php 
// Total Revenue by product
$query = "SELECT ProductName, Revenue FROM ecommerce.ProductsVsCustomers_Pivot ORDER BY Revenue DESC limit 10";
$title = "Products by revenues";
query_and_print_graph($query, $title, "Euros");
?>
	
	<p>The chart below shows the results of a similar analysis, this time to rank the customers that contribute the most to total revenues. Only the top 20 customers are shown below.</p>
	
<?php 
// Page body. Write here your queries
$query = "SELECT b.CustomerID Customer, sum(a.Quantity*a.UnitPrice) Revenues from ecommerce.order_details a left join ecommerce.orders b on a.OrderID=b.OrderID group by CustomerID order by Revenues desc limit 20";
$title = "Customers by revenues";
query_and_print_graph($query, $title, "Euros");
开发者ID:rogercusco,项目名称:bgse-dashboard-project,代码行数:31,代码来源:data_and_analysis.php

示例13: update_tax_brackets

function update_tax_brackets($table, $low, $high, $update, $value, $test)
{
    if ($GLOBALS['$connected'] == False) {
        connect_to_db();
    }
    $sql1 = mysql_query("UPDATE {$table} SET {$high}='{$update}' WHERE id='{$value}'") or die(mysql_error());
    if ($test == 1) {
        $temp = $value + 1;
        $sql2 = "SELECT {$high} FROM {$table} WHERE id='{$value}'";
        $result2 = mysql_query($sql2);
        $row2 = @mysql_fetch_array($result2);
        $low_update = $row2[$high] + 1;
        $sql3 = mysql_query("UPDATE {$table} SET {$low}='{$low_update}' WHERE id='{$temp}'") or die(mysql_error());
    }
}
开发者ID:patthickey,项目名称:software_engineering,代码行数:15,代码来源:sql_calls.php

示例14: addFile

function addFile($conn, $filename, $filetype, $filesize, $contents, $myID)
{
    //check to see if file with the same name exists, if it does, then we update that
    $statement = $conn->prepare("SELECT * FROM files where name = ? AND userid = ?");
    $statement->bind_param("si", $filename, $myID);
    $statement->execute();
    $error = $statement->error;
    $result = $statement->get_result();
    $statement->close();
    if ($error) {
        return $error;
    }
    //update existing file
    if ($result->num_rows > 0) {
        $newConn = connect_to_db(1);
        $statement = $newConn->prepare("UPDATE files SET type = ?, size = ?, content = ? WHERE userid = ? AND name = ?");
        $statement->bind_param("sisis", $filetype, $filesize, $contents, $myID, $filename);
    } else {
        $statement = $conn->prepare("INSERT INTO files (name, type, size, content, userid) VALUES (?, ?, ?, ?, ?)");
        $statement->bind_param("ssisi", $filename, $filetype, $filesize, $contents, $myID);
    }
    $statement->execute();
    $error = $statement->error;
    $statement->close();
    if (isset($newConn)) {
        $newConn->close();
    }
    return $error;
}
开发者ID:RITSPARSA,项目名称:ISTS14_CTF,代码行数:29,代码来源:functions.php

示例15: connect_to_db

<?php

include 'dbconn.php';
?>
<!DOCTYPE html>
<head>
<title>Selecting Multiple Records</title>
</head>
<body>
<?php 
$dbc = connect_to_db("jed");
$query = "select lastname, firstname from student";
$result = perform_query($dbc, $query);
echo "<ul>\n";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $firstname = $row['firstname'];
    $lastname = $row['lastname'];
    echo "<li>{$firstname}  {$lastname} </li>\n";
}
echo "</ul>\n";
disconnect_from_db($dbc, $result);
?>
</body>
</html>
开发者ID:lowriek,项目名称:CSCI1154_Examples,代码行数:24,代码来源:select_multiple.php


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