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


PHP db_connection函数代码示例

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


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

示例1: modif_mdp

function modif_mdp($newpw)
{
    $login = $_SESSION['login'];
    $db = db_connection();
    $req = $db->prepare('UPDATE db_login
  SET mdp = ?
  WHERE login = ?');
    $req->execute(array($newpw, $login));
}
开发者ID:Ahmed-R,项目名称:CRM_NFE114,代码行数:9,代码来源:db_pw_modif.php

示例2: clean

/**
 * clean data
 */
function clean(&$data)
{
    foreach ($data as $key => $post) {
        if (is_array($post)) {
            clean($post);
        } else {
            $clean[$key] = strip_tags(mysql_real_escape_string($post, db_connection()));
        }
    }
    $data = $clean;
}
开发者ID:platform-project,项目名称:platform-project,代码行数:14,代码来源:sanitize.php

示例3: insert_persona

function insert_persona($persona)
{
    include_once 'db_connection.php';
    if (!($conn = db_connection('localhost', 'root', '', 'academia'))) {
        return false;
    }
    // var_dump($conn);
    // mysqli_select_db($conn, "academia");
    // echo $persona->to_sql();
    if ($q = mysqli_query($conn, $persona->to_sql())) {
        mysqli_close($conn);
        return true;
    }
    return false;
}
开发者ID:JoseCardonaFigueroa,项目名称:crud-php,代码行数:15,代码来源:insert_persona.php

示例4: i18n_setLanguage

function i18n_setLanguage($lang)
{
    global $common_language;
    if ($lang == 'C') {
        setcookie('synchrotronLanguage', '', 0, $auth_path);
        unset($GLOBALS['common_language']);
        unset($common_language);
        unset($_COOKIE['synchrotronLanguage']);
        return;
    }
    $db = db_connection();
    sql_addToWhereClause($where, 'WHERE', 'code', '=', $lang);
    $query = db_query($db, "select id from languages {$where};");
    if (db_numRows($query) > 0) {
        list($common_language) = db_row($query, 0);
        $common_language = intval($common_language);
    }
}
开发者ID:KDE,项目名称:synchrotron,代码行数:18,代码来源:i18n.php

示例5: exec_query

function exec_query($query)
{
    $connection = db_connection();
    $result = $connection->query($query);
    if (!$result) {
        die("The query is invalid.<br/>");
    }
    $result_in_arr = array();
    if (explode(" ", $query)[0] == "SELECT") {
        while ($db_record = $result->fetch_assoc()) {
            foreach ($db_record as $key => $value) {
                $result_in_arr[$key] = $value;
            }
        }
        $result->free_result();
    }
    $connection->close();
    return $result_in_arr;
}
开发者ID:GStoykov,项目名称:Concept-map-api,代码行数:19,代码来源:service_db_operations.php

示例6: get_personas

function get_personas()
{
    include_once 'db_connection.php';
    $conn = db_connection('localhost', 'root', '', 'academia');
    $sql = "SELECT * FROM personas;";
    $personas = array();
    $errors = array();
    if ($query = mysqli_query($conn, $sql)) {
        while ($row = mysqli_fetch_assoc($query)) {
            $personas[] = $row;
        }
    } else {
        $errors[] = mysqli_error($conn);
    }
    mysqli_close($conn);
    if (empty($errors)) {
        return $personas;
    }
    return array('errors' => $errors);
}
开发者ID:JoseCardonaFigueroa,项目名称:crud-php,代码行数:20,代码来源:get_personas.php

示例7: htmlspecialchars

        $fdate = htmlspecialchars($_POST['due_date']);
        /*if(preg_match('/[^\w\s]/i', $fname) || preg_match('/[^\w\s]/i', $lname)) {
        			fail('Invalid name provided.');
        		}
        		if( empty($fname) || empty($lname) ) {
        			fail('Please enter a first and last name.');
        		}
        		if( empty($gender) ) {
        			fail('Please select a gender.');
        		}
        		if( empty($minutes) || empty($seconds) ) {
        			fail('Please enter minutes and seconds.');
        		}*/
        //$time = $minutes.":".$seconds;
        $query = "INSERT INTO assignments SET course_name='{$fcourse}', course_code='{$fcode}', assignment_name='{$fname}', due_date='{$fdate}'";
        $result = db_connection($query);
        if ($result) {
            $msg = "Assignment: " . $fcode . " " . $fname . " added successfully";
            success($msg);
        } else {
            fail('Insert failed.');
        }
        exit;
    }
}
function fail($message)
{
    die(json_encode(array('status' => 'fail', 'message' => $message)));
}
function success($message)
{
开发者ID:kmCha,项目名称:Assignment,代码行数:31,代码来源:assignments.php

示例8: processProviderAssets

function processProviderAssets($assets, $packageBasePath, $provider, $providerId, $config)
{
    global $verbose;
    $metadataPath = $config['metadata'];
    if (empty($metadataPath)) {
        $metadataPath = 'metadata.desktop';
    }
    $recreateCategoriesFile = false;
    $categories = array();
    $db = db_connection('write');
    foreach ($assets as $asset => $path) {
        if ($verbose) {
            print "Processing {$providerId} {$asset} at {$path}\n";
        }
        if (!is_file("{$path}/{$metadataPath}")) {
            if ($verbose) {
                print "No such thing as {$path}/{$metadataPath}, perhaps it was deleted?\n";
            }
            deleteAsset($providerId, $asset);
            continue;
        }
        $metadata = new INIFile("{$path}/{$metadataPath}");
        $plugin = $metadata->getValue('X-KDE-PluginInfo-Name', 'Desktop Entry');
        if (empty($plugin)) {
            print "No X-KDE-PluginInfo-Name entry in {$path}/{$metadataPath}\n";
            continue;
        }
        $packageFile = $metadata->getValue('X-Synchrotron-ContentUrl', 'Desktop Entry');
        $externalPackage = !empty($packageFile);
        if (!$externalPackage) {
            $packageFile = createPackage($plugin, $path, $packageBasePath, $config);
        }
        if (!$packageFile) {
            deleteAsset($providerId, $asset);
            continue;
        }
        $category = $metadata->getValue('X-KDE-PluginInfo-Category', 'Desktop Entry');
        if (empty($category)) {
            $category = 'Miscelaneous';
        }
        if (isset($categories[$category])) {
            $categoryId = $categories[$category];
        } else {
            unset($where);
            sql_addToWhereClause($where, '', 'provider', '=', $providerId);
            global $db_type;
            if ($db_type == 'postgres') {
                sql_addToWhereClause($where, 'and', 'name', 'ILIKE', $category);
            } else {
                sql_addToWhereClause($where, 'and', 'name', 'LIKE', $category);
            }
            $query = db_query($db, "SELECT id FROM categories WHERE {$where}");
            if (db_numRows($query) < 1) {
                unset($fields, $values);
                sql_addIntToInsert($fields, $values, 'provider', $providerId);
                sql_addScalarToInsert($fields, $values, 'name', $category);
                db_insert($db, 'categories', $fields, $values);
                $query = db_query($db, "SELECT id FROM categories WHERE {$where}");
                $recreateCategoriesFile = true;
            }
            list($categoryId) = db_row($query, 0);
            $categories[$category] = $categoryId;
        }
        unset($where);
        sql_addToWhereClause($where, '', 'provider', '=', $providerId);
        sql_addToWhereClause($where, 'and', 'id', '=', $plugin);
        $query = db_query($db, "select * from content where {$where};");
        if (db_numRows($query) > 0) {
            // just update the field
            unset($fields);
            sql_addScalarToUpdate($fields, 'version', $metadata->getValue('X-KDE-PluginInfo-Version', 'Desktop Entry'));
            sql_addScalarToUpdate($fields, 'author', $metadata->getValue('X-KDE-PluginInfo-Author', 'Desktop Entry'));
            sql_addScalarToUpdate($fields, 'homepage', $metadata->getValue('X-KDE-PluginInfo-Website', 'Desktop Entry'));
            //FIXME: get preview image from asset dir! sql_addScalarToUpdate($fields, 'preview', <image path>);
            sql_addScalarToUpdate($fields, 'name', $metadata->getValue('Name', 'Desktop Entry'));
            // FIXME: i18n
            sql_addScalarToUpdate($fields, 'description', $metadata->getValue('Comment', 'Desktop Entry'));
            sql_addIntToUpdate($fields, 'category', $categoryId);
            sql_addRawToUpdate($fields, 'updated', 'current_timestamp');
            sql_addScalarToUpdate($fields, 'package', $packageFile);
            sql_addBoolToUpdate($fields, 'externalPackage', $externalPackage);
            db_update($db, 'content', $fields, $where);
        } else {
            // new asset!
            unset($fields, $values);
            sql_addIntToInsert($fields, $values, 'provider', $providerId);
            sql_addScalarToInsert($fields, $values, 'id', $plugin);
            sql_addScalarToInsert($fields, $values, 'version', $metadata->getValue('X-KDE-PluginInfo-Version', 'Desktop Entry'));
            sql_addScalarToInsert($fields, $values, 'author', $metadata->getValue('X-KDE-PluginInfo-Author', 'Desktop Entry'));
            sql_addScalarToInsert($fields, $values, 'homepage', $metadata->getValue('X-KDE-PluginInfo-Website', 'Desktop Entry'));
            //FIXME: get preview image from asset dir! sql_addScalarToInsert($fields, $values, 'preview', <image path>);
            sql_addScalarToInsert($fields, $values, 'name', $metadata->getValue('Name', 'Desktop Entry'));
            // FIXME: i18n
            sql_addScalarToInsert($fields, $values, 'description', $metadata->getValue('Comment', 'Desktop Entry'));
            sql_addIntToInsert($fields, $values, 'category', $categoryId);
            sql_addScalarToInsert($fields, $values, 'package', $packageFile);
            sql_addBoolToInsert($fields, $values, 'externalPackage', $externalPackage);
            db_insert($db, 'content', $fields, $values);
        }
    }
//.........这里部分代码省略.........
开发者ID:KDE,项目名称:synchrotron,代码行数:101,代码来源:scan.php

示例9: install_done

function install_done()
{
    global $output, $db, $mybb, $errors, $cache, $lang;
    if (empty($mybb->input['adminuser'])) {
        $errors[] = $lang->admin_step_error_nouser;
    }
    if (empty($mybb->input['adminpass'])) {
        $errors[] = $lang->admin_step_error_nopassword;
    }
    if ($mybb->input['adminpass'] != $mybb->input['adminpass2']) {
        $errors[] = $lang->admin_step_error_nomatch;
    }
    if (empty($mybb->input['adminemail'])) {
        $errors[] = $lang->admin_step_error_noemail;
    }
    if (is_array($errors)) {
        create_admin_user();
    }
    require MYBB_ROOT . 'inc/config.php';
    $db = db_connection($config);
    require MYBB_ROOT . 'inc/settings.php';
    $mybb->settings =& $settings;
    ob_start();
    $output->print_header($lang->finish_setup, 'finish');
    echo $lang->done_step_usergroupsinserted;
    // Insert all of our user groups from the XML file
    $settings = file_get_contents(INSTALL_ROOT . 'resources/usergroups.xml');
    $parser = new XMLParser($settings);
    $parser->collapse_dups = 0;
    $tree = $parser->get_tree();
    $admin_gid = '';
    $group_count = 0;
    foreach ($tree['usergroups'][0]['usergroup'] as $usergroup) {
        // usergroup[cancp][0][value]
        $new_group = array();
        foreach ($usergroup as $key => $value) {
            if ($key == "gid" || !is_array($value)) {
                continue;
            }
            $new_group[$key] = $db->escape_string($value[0]['value']);
        }
        $return_gid = $db->insert_query("usergroups", $new_group);
        // If this group can access the admin CP and we haven't established the admin group - set it (just in case we ever change IDs)
        if ($new_group['cancp'] == 1 && !$admin_gid) {
            $admin_gid = $return_gid;
        }
        $group_count++;
    }
    echo $lang->done . '</p>';
    echo $lang->done_step_admincreated;
    $now = TIME_NOW;
    $salt = random_str();
    $loginkey = generate_loginkey();
    $saltedpw = md5(md5($salt) . md5($mybb->input['adminpass']));
    $newuser = array('username' => $db->escape_string($mybb->input['adminuser']), 'password' => $saltedpw, 'salt' => $salt, 'loginkey' => $loginkey, 'email' => $db->escape_string($mybb->input['adminemail']), 'usergroup' => $admin_gid, 'regdate' => $now, 'lastactive' => $now, 'lastvisit' => $now, 'website' => '', 'icq' => '', 'aim' => '', 'yahoo' => '', 'msn' => '', 'birthday' => '', 'signature' => '', 'allownotices' => 1, 'hideemail' => 0, 'subscriptionmethod' => '0', 'receivepms' => 1, 'pmnotice' => 1, 'pmnotify' => 1, 'remember' => 1, 'showsigs' => 1, 'showavatars' => 1, 'showquickreply' => 1, 'invisible' => 0, 'style' => '0', 'timezone' => 0, 'dst' => 0, 'threadmode' => '', 'daysprune' => 0, 'regip' => $db->escape_string(get_ip()), 'longregip' => intval(ip2long(get_ip())), 'language' => '', 'showcodebuttons' => 1, 'tpp' => 0, 'ppp' => 0, 'referrer' => 0, 'buddylist' => '', 'ignorelist' => '', 'pmfolders' => '', 'notepad' => '', 'showredirect' => 1);
    $db->insert_query('users', $newuser);
    echo $lang->done . '</p>';
    echo $lang->done_step_adminoptions;
    $adminoptions = file_get_contents(INSTALL_ROOT . 'resources/adminoptions.xml');
    $parser = new XMLParser($adminoptions);
    $parser->collapse_dups = 0;
    $tree = $parser->get_tree();
    $insertmodule = array();
    $db->delete_query("adminoptions");
    // Insert all the admin permissions
    foreach ($tree['adminoptions'][0]['user'] as $users) {
        $uid = $users['attributes']['uid'];
        foreach ($users['permissions'][0]['module'] as $module) {
            foreach ($module['permission'] as $permission) {
                $insertmodule[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value'];
            }
        }
        $defaultviews = array();
        foreach ($users['defaultviews'][0]['view'] as $view) {
            $defaultviews[$view['attributes']['type']] = $view['value'];
        }
        $adminoptiondata = array('uid' => intval($uid), 'cpstyle' => '', 'notes' => '', 'permissions' => $db->escape_string(serialize($insertmodule)), 'defaultviews' => $db->escape_string(serialize($defaultviews)));
        $insertmodule = array();
        $db->insert_query('adminoptions', $adminoptiondata);
    }
    echo $lang->done . '</p>';
    // Automatic Login
    my_unsetcookie("sid");
    my_unsetcookie("mybbuser");
    my_setcookie('mybbuser', $uid . '_' . $loginkey, null, true);
    ob_end_flush();
    // Make fulltext columns if supported
    if ($db->supports_fulltext('threads')) {
        $db->create_fulltext_index('threads', 'subject');
    }
    if ($db->supports_fulltext_boolean('posts')) {
        $db->create_fulltext_index('posts', 'message');
    }
    // Register a shutdown function which actually tests if this functionality is working
    add_shutdown('test_shutdown_function');
    echo $lang->done_step_cachebuilding;
    require_once MYBB_ROOT . 'inc/class_datacache.php';
    $cache = new datacache();
    $cache->update_version();
    $cache->update_attachtypes();
//.........这里部分代码省略.........
开发者ID:benn0034,项目名称:SHIELDsite2.old,代码行数:101,代码来源:index.php

示例10: is_validated

function is_validated($email)
{
    $con = db_connection();
    $email = mysql_real_escape_string($string);
    $result = mysql_query("SELECT validated FROM users WHERE email='{$email}'");
    if (mysql_num_rows($result) > 0) {
        $validated = int_to_bool(mysql_result($result, 0));
        db_close($con);
        return $result;
    } else {
        return false;
    }
}
开发者ID:qiemem,项目名称:GovDialogue,代码行数:13,代码来源:usermanagement.php

示例11: db_connection

<?php

require_once "conf/db_connection.php";
require_once "header.php";
require_once "left_nav.php";
?>
<div id="content">
<br />
<center>

<?php 
db_connection();
$query = "SELECT max(id_producto) as 'maximo' FROM producto";
$result = mysql_query($query);
$datos = mysql_fetch_array($result);
$r1 = rand(14, $datos["maximo"]);
$r2 = rand(14, $datos["maximo"]);
$r3 = rand(14, $datos["maximo"]);
$query = "SELECT * FROM producto WHERE id_producto IN ({$r1},{$r2},{$r3})";
$result = mysql_query($query);
while ($datos = mysql_fetch_array($result)) {
    $id = $datos["id_producto"];
    $nombre = $datos["nombre"];
    $precio = $datos["precio"];
    $img = $datos["imagen"];
    //$img = "<img src=\'". $image ."' width=\'100\' height=\'100\' />";
    echo " <img src='" . $datos["imagen"] . "'  width='100' height='100' /> <br /><br />  <a href='catalogo.php?id=" . $datos["id_producto"] . "&desc=" . $datos["descripcion"] . "&nom=" . $datos["nombre"] . "'>" . $datos["nombre"] . "  </a><span class='precio'>RD\$ " . $datos["precio"] . ".00</span><a href='catalogo.php?id=" . $datos["id_producto"] . "&desc=" . $datos["descripcion"] . "&nom=" . $datos["nombre"] . "'>&nbsp;&nbsp;<img src='imagen/ordenar.png' with='30' height='30' /></a>&nbsp;<a id='add' onclick='addcart({$id},\"{$nombre}\",{$precio},1,\"{$img}\");'><img src='imagen/addtocart2.jpg' with='30' height='30' id='icart' /></a><br /><br /><br />";
}
?>
</center>
</div>
开发者ID:natiums8311,项目名称:Proyectos_Otros,代码行数:31,代码来源:index.php

示例12: printHeader

if (!canAccessApi($_SERVER['REMOTE_ADDR'])) {
    printHeader(0, 0, 0, _("Too many requests from {$_SERVER['REMOTE_ADDR']}"), 200);
    printFooter();
    exit;
}
$pagesize = intval($_GET['pagesize']);
$page = max(0, intval($_GET['page']));
$searchTerm = $_GET['search'];
$sortMode = $_GET['sortmode'];
$provider = $_GET['provider'];
if (empty($provider)) {
    printHeader(0, $pagesize, 0, _("Invalid provider"));
    printFooter();
    exit;
}
$db = db_connection();
unset($where);
sql_addToWhereClause($where, '', 'p.name', '=', $provider);
$updatedSince = intval($_GET['updatedsince']);
if ($updatedSince > 0) {
    sql_addToWhereClause($where, 'and', "extract('epoch' from c.updated)", '>=', $updatedSince);
}
$createdSince = intval($_GET['createdsince']);
if ($createdsince > 0) {
    sql_addToWhereClause($where, 'and', "extract('epoch' from c.created)", '>=', $createdSince);
}
list($totalItemCount) = db_row(db_query($db, "SELECT count(c.id) FROM content c LEFT JOIN providers p ON (c.provider = p.id) WHERE {$where};"), 0);
if ($totalItemCount < 1) {
    printHeader(0, $pagesize);
    printFooter();
    exit;
开发者ID:KDE,项目名称:synchrotron,代码行数:31,代码来源:list.php

示例13: query_full_day

function query_full_day($date, $scope)
{
    //
    // Used to generate all three of the "current" charts that shows daily activity.
    //
    $connection = db_connection();
    // should always a date, and should always be formatted YYYY-MM-DD
    // not always a scope, but always an int if there is one.
    if ($date == date("Y-m-d")) {
        // if the date is today...
        if (isset($scope)) {
            // ...and it's scoped.
            $whereClause = "date > DATE_SUB(NOW(), INTERVAL " . $scope . " HOUR)";
        } else {
            // ...with no scope.
            $whereClause = "date(date) = date(NOW())";
        }
    } else {
        // It's not today...
        if (isset($scope)) {
            // ...but it is scoped.
            $whereClause = "date > DATE_SUB(DATE_ADD(date('" . $date . "'), INTERVAL 1 DAY), INTERVAL " . $scope . " HOUR) AND\n\t\t\t\t\t\t\tdate < DATE_ADD(date('" . $date . "'), INTERVAL 1 DAY)";
        } else {
            // ...with no scope.
            $whereClause = "date(date) = date('" . $date . "')";
        }
    }
    $query_summary = "SELECT *\n\t\t\t\t\t\tFROM monitormate_summary\n\t\t\t\t\t\tWHERE date(date) = date('" . $date . "')\n\t\t\t\t\t\tORDER BY date";
    // WHERE ".$whereClause."
    $query_cc = "SELECT *\n\t\t\t\t\t\tFROM monitormate_cc\n\t\t\t\t\t\tWHERE " . $whereClause . "\n\t\t\t\t\t\tORDER BY date";
    // if there's more than one charge controller (fm/mx) we should get the cc totals.
    $query_cc_totals = "SELECT date, SUM(charge_current) AS total_current, battery_voltage\n\t\t\t\t\t\tFROM `monitormate_cc`\n\t\t\t\t\t\tWHERE " . $whereClause . "\n\t\t\t\t\t\tGROUP BY date\n\t\t\t\t\t\tORDER BY date";
    $query_fndc = "SELECT *\n\t\t\t\t\t\tFROM monitormate_fndc\n\t\t\t\t\t\tWHERE " . $whereClause . "\n\t\t\t\t\t\tORDER BY date";
    $query_fx = "SELECT *\n\t\t\t\t\t\tFROM monitormate_fx\n\t\t\t\t\t\tWHERE " . $whereClause . "\n\t\t\t\t\t\tORDER BY date";
    $query_radian = "SELECT *\n\t\t\t\t\t\tFROM monitormate_radian\n\t\t\t\t\t\tWHERE " . $whereClause . "\n\t\t\t\t\t\tORDER BY date";
    $result_summary = mysql_query($query_summary, $connection);
    $result_cc = mysql_query($query_cc, $connection);
    $result_fndc = mysql_query($query_fndc, $connection);
    $result_fx = mysql_query($query_fx, $connection);
    $result_radian = mysql_query($query_radian, $connection);
    $full_day_querys = array("cc" => $result_cc, "fndc" => $result_fndc, "fx" => $result_fx, "radian" => $result_radian);
    // Summary only needs to net values to be computed, then add to full_day_data
    while ($row = mysql_fetch_assoc($result_summary)) {
        set_elementTypes($row);
        // row passed as a reference.
        $row['kwh_net'] = $row['kwh_in'] - $row['kwh_out'];
        $row['ah_net'] = $row['ah_in'] - $row['ah_out'];
        $full_day_data["summary"] = $row;
    }
    // All other queries need a proper timestamp added.
    foreach ($full_day_querys as $i) {
        while ($row = mysql_fetch_assoc($i)) {
            set_elementTypes($row);
            // row passed as a reference.
            $timestamp = strtotime($row['date']) * 1000;
            // get timestamp in seconds, convert to milliseconds
            $stampedRow = array("timestamp" => $timestamp) + $row;
            // put it in an assoc array and merge them
            $full_day_data[$row["device_id"]][$row["address"]][] = $stampedRow;
        }
    }
    // there's more than one charge controller, query the totals, timestamp them and add them.
    if (count($full_day_data[3]) > 1) {
        $result_cc_totals = mysql_query($query_cc_totals, $connection);
        while ($row = mysql_fetch_assoc($result_cc_totals)) {
            set_elementTypes($row);
            // row passed as a reference.
            $timestamp = strtotime($row['date']) * 1000;
            // get timestamp in seconds, convert to milliseconds
            $stampedRow = array("timestamp" => $timestamp) + $row;
            // put it in an assoc array and merge them
            $full_day_data[3]["totals"][] = $stampedRow;
        }
    }
    if (isset($_GET["debug"])) {
        echo $query_cc . '<br/>';
        echo '<pre>';
        print_r($full_day_data);
        echo '</pre>';
    } else {
        $json_full_day = json_encode($full_day_data);
        echo $json_full_day;
    }
}
开发者ID:TheRinger,项目名称:monitormate,代码行数:84,代码来源:getstatus.php

示例14: db_delete

function db_delete($id)
{
    $db = db_connection();
    return db_backend_delete($db, intval($id));
}
开发者ID:T1T4N,项目名称:ncrypt,代码行数:5,代码来源:db.inc.php

示例15: db_connection

}
// Attempt a save of the database connection details
$error_message = false;
if ($_SESSION['x7chat_install']['type'] == 'install' && (!empty($_POST) && $_SESSION['x7chat_install']['step'] === 1 || $_SESSION['x7chat_install']['step'] === 2 && !$db && !empty($_SESSION['x7chat_install']['config_contents']))) {
    try {
        if ($_SESSION['x7chat_install']['step'] === 1) {
            $check_db = db_connection($_POST);
            $_SESSION['x7chat_install']['config_contents'] = $contents = '<?php return ' . var_export(array('user' => $_POST['user'], 'pass' => $_POST['pass'], 'dbname' => $_POST['dbname'], 'host' => $_POST['host'], 'prefix' => $_POST['prefix'], 'auth_plugin' => '', 'auth_api_endpoint' => '', 'api_key' => hash('sha256', microtime(TRUE) . print_r($_SERVER, 1) . mt_rand(0, mt_getrandmax()) . crypt(mt_rand(0, mt_getrandmax()) . microtime(TRUE) . print_r($_SERVER, 1))), 'debug' => false), 1) . ';';
        } else {
            $contents = $_SESSION['x7chat_install']['config_contents'];
        }
        if (is_writable('../config.php')) {
            $written = file_put_contents('../config.php', $contents);
            if ($written) {
                $config = (require '../config.php');
                $db = db_connection($config);
            }
        } else {
            $written = false;
        }
        $_SESSION['x7chat_install']['step'] = 2;
    } catch (Exception $ex) {
        $error_message = "The connection to the database failed: {$ex->getMessage()}";
    }
}
// Check configuration file for valid values & setup database tables
if ($_SESSION['x7chat_install']['step'] === 2 && $_SESSION['x7chat_install']['type'] == 'install') {
    if ($db) {
        unset($_SESSION['x7chat_install']['config_contents']);
        try {
            patch_sql($db, $config['prefix']);
开发者ID:SkyFire-Lee,项目名称:x7chat,代码行数:31,代码来源:index.php


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