本文整理汇总了PHP中connect_database函数的典型用法代码示例。如果您正苦于以下问题:PHP connect_database函数的具体用法?PHP connect_database怎么用?PHP connect_database使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect_database函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect_database
/**
* Connect to the FluxBB database
*
* @param array $db_config
*/
function connect_database($db_config)
{
$this->db_config = $db_config;
$this->db = connect_database($db_config);
$this->db->set_names('utf8');
return $this->db;
}
示例2: delete_app
function delete_app($params)
{
global $user, $module;
$db = connect_database();
$db->delete('app', 'id = ' . $params[0] . ' AND owner = ' . $user['id']);
redirect($module, 'developer');
}
示例3: transaksi
function transaksi()
{
include "config.php";
$conn = connect_database();
if (userCheck($conn, $_POST['id'])) {
$kodealat = mysqli_real_escape_string($conn, $_POST["kode-alat"]);
$tanggal = date("Y-m-d", time());
if (isset($_POST["tanggal-pinjam"])) {
$tanggal = $_POST["tanggal-pinjam"];
}
if (!isAvailable($conn, $kodealat, $tanggal, $_POST["tanggal-kembali"])) {
echo "Maaf, alat pada hari tersebut tidak dapat dipinjam </br>";
} else {
if (strcmp($_POST["jenis"], "peminjaman") == 0) {
$sql = "INSERT INTO `peminjaman` (`id_user`, `id_alat`, `tanggal_rencana_pengembalian`) VALUES ('{$_POST['id']}','{$kodealat}','" . str_replace('T', ' ', $_POST["tanggal-kembali"]) . ":00')";
} else {
//booking
$sql = "INSERT INTO `booking` (`id_user`, `id_alat`, `tanggal_rencana_peminjaman`, `tanggal_rencana_pengembalian`) VALUES ('{$_POST['id']}','{$kodealat}','" . str_replace('T', ' ', $_POST["tanggal-pinjam"]) . ":00','" . str_replace('T', ' ', $_POST["tanggal-kembali"]) . ":00')";
}
if (mysqli_query($conn, $sql)) {
echo "Data anda berhasil disimpan</br>";
} else {
echo mysqli_error($conn);
}
}
} else {
//tidak ada user dengan id tersebut
echo "Maaf, user dengan ID sekian belum terdaftar. Mohon daftarkan diri Anda terlebih dahulu!";
}
echo '<a href="../index.php"> Kembali ke halaman Transaksi</a>';
}
示例4: load_questions
function load_questions()
{
$db = connect_database();
$resp = array();
$results = $db->query("SELECT * FROM Question");
while ($row = $results->fetch_array()) {
$resp[] = array('q' => $row['question'], 'a1' => $row['answer_1'], 'a2' => $row['answer_2'], 'a3' => $row['answer_3'], 'a4' => $row['answer_4']);
}
return $resp;
}
示例5: addData
public function addData()
{
$con = connect_database();
$sql = " INSERT INTO sach (IDtheloai, tacgia, tensach, ";
$sql .= " noidungtomtat, giaban, namxuatban) ";
$sql .= " VALUES ({$_POST['theloai']}, {$_POST['tacgia']}, ";
$sql .= " {$_POST['tensach']}, {$_POST['noidung']}, ";
$sql .= " {$_POST['giaban']}, {$_POST['namxuatban']})";
mysqli_query($con, $sql);
}
示例6: index
function index($params)
{
$db = connect_database();
$query = gzuncompress(base64_decode(file_get_contents('php://input')));
$data = $db->query($query);
$dat = array();
while ($row = row_assoc($data)) {
$dat[] = $row;
}
$data = base64_encode(gzcompress(json_encode($dat)));
die($data);
}
示例7: database
function database($params)
{
/*global $table_schema;
write_schema('dbtable', $table_schema);*/
$data = array();
$db = connect_database();
//
if (isset($params['sql']) && is_array($params['sql'])) {
foreach ($params['sql'] as $sql) {
if (trim($sql) != '') {
$db->query($sql);
}
}
}
//
$data['import'] = @unserialize(gzinflate(file_get_contents('data/schema.db')));
if (!$data['import']) {
$data['import'] = array();
}
//print_r($file);
//
$tables = $db->query('SHOW tables');
$data['tables'] = array();
while ($table = row_array($tables)) {
$columns = $db->query('DESCRIBE `' . $table[0] . '`');
$tmp = array();
$cname = '';
while ($column = row_assoc($columns)) {
$field = $column['Field'];
unset($column['Field']);
$size = explode('(', $column['Type']);
$column['Type'] = $size[0];
$column['Size'] = count($size) == 2 ? str_replace(')', '', $size[1]) : '';
$tmp[$field] = $column;
}
$data['tables'][$table[0]] = $tmp;
}
$data['schema'] = load_schema('dbtable');
//
if (isset($params[0]) && $params[0] == 'export') {
// CHECK IF THERE ARE CONFLICTS
$result = file_put_contents('data/schema.db', gzdeflate(serialize($data['tables'])));
if ($result) {
flash_message('Database schema is exported', 'success');
} else {
flash_message('No permission to write to data/schema.db', 'warning');
}
redirect('admin/developer', 'database');
}
//
$data['html_head'] = array('title' => 'Database');
return $data;
}
示例8: add
function add()
{
include "config.php";
$conn = connect_database();
$sql = "INSERT INTO `alat` (`id_alat`, `nama_alat`, `status`, `lokasi`) VALUES ('{$_POST['idalat']}', '{$_POST['namaalat']}','{$_POST['status']}','{$_POST['lokasi']}');";
if (mysqli_query($conn, $sql)) {
echo "Data anda berhasil disimpan";
echo '<a href="../peralatan.php"> Kembali ke halaman Peralatan</a>';
} else {
echo mysqli_error($conn);
echo '<a href="../peralatan.php"> Kembali ke halaman Peralatan</a>';
}
}
示例9: add
function add()
{
include "config.php";
$conn = connect_database();
$sql = "INSERT INTO `user` (`id_user`, `nama_user`, `kategori_civitas`) VALUES ('{$_POST['iduser']}', '{$_POST['namauser']}','{$_POST['kategori']}');";
if (mysqli_query($conn, $sql)) {
echo "Data anda berhasil disimpan";
echo '<a href="../pengguna.php"> Kembali ke halaman Pengguna</a>';
} else {
echo mysqli_error($conn);
echo '<a href="../pengguna.php"> Kembali ke halaman Pengguna</a>';
}
}
示例10: _generic_page
function _generic_page($params)
{
global $lex, $lang, $page;
$db = connect_database();
//
$content = $db->query('SELECT title, content FROM content WHERE lang = \'' . $lang . '\' AND slug = \'' . str_replace('_', '-', $page) . '\'');
if ($data = row_assoc($content)) {
} else {
$data = array('title' => $lex['not-found'], 'content' => '<p>' . $lex['translation-not-found'] . '</p>');
}
//
$data['page'] = $page;
$data['html_head'] = array('title' => $data['title'], 'description' => shorten_string($data['title'], 250));
return $data;
}
示例11: draw_graph
function draw_graph($month, $year, $permintaan, $user)
{
include "controller/config.php";
$conn = connect_database();
$waktu = $year * 12 + $month;
if ($permintaan == "penggunaan-alat") {
$sql = "select id_alat,nama_alat, tanggal_peminjaman as mulai, tanggal_rencana_pengembalian as selesai from peminjaman NATURAL JOIN alat WHERE (year(tanggal_peminjaman)*12+month(tanggal_peminjaman))<={$waktu} and (year(tanggal_rencana_pengembalian)*12+month(tanggal_rencana_pengembalian))>={$waktu} ORDER BY nama_alat;";
} else {
if ($permintaan == "perbaikan-alat") {
$sql = "select id_alat,nama_alat, tanggal_mulai_perbaikan as mulai, estimasi_selesai_perbaikan as selesai from perbaikan NATURAL JOIN alat WHERE (year(tanggal_mulai_perbaikan)*12+month(tanggal_mulai_perbaikan))<={$waktu} and (year(estimasi_selesai_perbaikan)*12+month(estimasi_selesai_perbaikan))>={$waktu} ORDER BY nama_alat;";
} else {
if ($permintaan == "penggunaan-alat-user") {
$sql = "select id_alat,nama_alat,tanggal_peminjaman as mulai, tanggal_rencana_pengembalian as selesai from peminjaman NATURAL JOIN alat NATURAL JOIN user WHERE kategori_civitas = '{$user}' and(year(tanggal_peminjaman)*12+month(tanggal_peminjaman))<={$waktu} and (year(tanggal_rencana_pengembalian)*12+month(tanggal_rencana_pengembalian))>={$waktu} ORDER BY nama_alat;";
}
}
}
$results = mysqli_query($conn, $sql);
if (mysqli_num_rows($results) > 0) {
$days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
$akhir_bulan = $year * 365 + $month * 30 + $days_in_month;
$awal_bulan = $year * 365 + $month * 30 + 1;
$nama = array();
while ($row = $results->fetch_assoc()) {
$waktu_mulai = intval(substr($row['mulai'], 0, 4)) * 365 + intval(substr($row['mulai'], 5, 2)) * 30 + intval(substr($row['mulai'], 8, 2));
$waktu_selesai = intval(substr($row['selesai'], 0, 4)) * 365 + intval(substr($row['selesai'], 5, 2)) * 30 + intval(substr($row['selesai'], 8, 2));
if ($row['nama_alat'] != end($nama)) {
array_push($nama, $row['nama_alat']);
}
}
$arr = array("chart" => array("type" => 'column'), "title" => array("text" => $permintaan . " bulan " . $month . " tahun " . $year), "xAxis" => array("type" => "category"), "yAxis" => array("min" => 0, "title" => 'Jumlah Occasion'), "legend" => array("enabled" => false), "plotOptions" => array("series" => array("borderWidth" => 0, "dataLabels" => array("enabled" => true, "format" => '{point.y:.1f}%'))), "tooltip" => array("headerFormat" => "<span style='font-size:11px'>{series.name}</span><br>", "pointFormat" => "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>"), "series" => array(array("name" => 'kejadian', "colorByPoint" => true, "data" => array(), "drilldown" => array("serries" => array()))));
$stat = json_encode($arr);
echo "<div id='graph' style='min-width: 310px; height: 400px; margin: 0 auto'></div>";
echo "<script type='text/javascript'>drawGraph({$stat})</script>";
} else {
if ($permintaan == "perbaikan-alat") {
echo "Tidak ada Perbaikan pada bulan " . $month . " tahun " . $year;
} else {
echo "Tidak ada Peminjaman pada bulan " . $month . " tahun " . $year;
}
}
mysqli_free_result($results);
}
示例12: blog
function blog($params)
{
$data = array();
$db = connect_database();
//
$page = 1;
if (isset($params[0]) && $params[0] > 0) {
$page = $params[0];
}
if (isset($params[1])) {
$data['article'] = mysql_fetch_assoc($db->query('SELECT id, published, title, content FROM blog WHERE id = ' . $params[1]));
} else {
$per_page = 5;
$data['blog'] = $db->query('SELECT id, published, title, content FROM blog ORDER BY published DESC LIMIT ' . $per_page * ($page - 1) . ', ' . $per_page);
$pages = mysql_fetch_array($db->query('SELECT COUNT(*) FROM blog'));
$data['pages'] = ceil($pages[0] / $per_page);
}
$data['page'] = $page;
//
$data['html_head'] = array('title' => 'Blog: Website Title');
return $data;
}
示例13: pengembalian
function pengembalian($nama)
{
include "config.php";
$conn = connect_database();
if (!empty($_POST["status"])) {
foreach ($_POST["status"] as $status) {
$pengembalian = explode("|", $status);
//foreach($pengembalian as $a) echo $a."|";
echo "<br>";
$sql = "UPDATE `peminjaman` SET `tanggal_pengembalian` = NOW() WHERE `id_user`=" . $pengembalian[0] . " AND `id_alat`='" . $pengembalian[1] . "' AND `tanggal_peminjaman`='" . $pengembalian[2] . "'";
//echo $sql."<br>";
if (mysqli_query($conn, $sql)) {
echo "Pengembalian peralatan dengan ID " . $pengembalian[1] . " dengan tanggal peminjaman " . $pengembalian[2] . " berhasil dilakukan.<br>";
} else {
echo mysqli_error($conn) . "<br>";
exit;
}
}
} else {
echo "Tidak ada peralatan yang dikembalikan.<br>";
}
echo '<a href="../pengembalian.php"> Kembali ke halaman Pengembalian</a>';
}
示例14: draw_graph
function draw_graph($month, $year, $permintaan, $user)
{
include "controller/config.php";
$conn = connect_database();
$waktu = $year * 12 + $month;
if ($permintaan == "penggunaan-alat") {
$sql = "select nama_alat,count(*) as count from peminjaman NATURAL JOIN alat WHERE (year(tanggal_peminjaman)*12+month(tanggal_peminjaman))<={$waktu} and (year(tanggal_rencana_pengembalian)*12+month(tanggal_rencana_pengembalian))>={$waktu} GROUP BY nama_alat";
} else {
if ($permintaan == "perbaikan-alat") {
$sql = "select nama_alat,count(*) as count from perbaikan NATURAL JOIN alat WHERE (year(tanggal_mulai_perbaikan)*12+month(tanggal_mulai_perbaikan))<={$waktu} and (year(estimasi_selesai_perbaikan)*12+month(estimasi_selesai_perbaikan))>={$waktu} GROUP BY nama_alat";
} else {
if ($permintaan == "penggunaan-alat-user") {
$sql = "select nama_alat,count(*) as count from peminjaman NATURAL JOIN alat NATURAL JOIN user WHERE kategori_civitas = '{$user}' and(year(tanggal_peminjaman)*12+month(tanggal_peminjaman))<={$waktu} and (year(tanggal_rencana_pengembalian)*12+month(tanggal_rencana_pengembalian))>={$waktu} GROUP BY nama_alat;";
}
}
}
$results = mysqli_query($conn, $sql);
if (mysqli_num_rows($results) > 0) {
$categories = array();
$jumlah = array();
while ($row = $results->fetch_assoc()) {
$categories[] = $row['nama_alat'];
$jumlah[] = intval($row['count']);
}
$arr = array("chart" => array("type" => 'column'), "title" => array("text" => $permintaan . " bulan " . $month . " tahun " . $year), "xAxis" => array("categories" => $categories, "crosshair" => true), "yAxis" => array("min" => 0, "title" => 'Jumlah Occasion'), "plotOptions" => array("column" => array("pointPadding" => 0.2, "borderWidth" => 0)), "series" => array(array("name" => 'kejadian', "data" => $jumlah)));
$stat = json_encode($arr);
echo "<div id='graph' style='min-width: 310px; height: 400px; margin: 0 auto'></div>";
echo "<script type='text/javascript'>drawGraph({$stat})</script>";
} else {
if ($permintaan == "perbaikan-alat") {
echo "Tidak ada Perbaikan pada bulan " . $month . " tahun " . $year;
} else {
echo "Tidak ada Peminjaman pada bulan " . $month . " tahun " . $year;
}
}
mysqli_free_result($results);
}
示例15: pengembalian
function pengembalian()
{
include "config.php";
$conn = connect_database();
if (!empty($_POST["check"])) {
foreach ($_POST["check"] as $check) {
$perbaikan = explode("|", $check);
echo "<br>";
$sql = "UPDATE `perbaikan` SET `tanggal_selesai_perbaikan` = NOW() WHERE `id_alat`='" . $perbaikan[0] . "' AND `nama_institusi`='" . $perbaikan[1] . "' AND `tanggal_mulai_perbaikan`='" . $perbaikan[2] . "'";
$sql1 = "UPDATE `alat` SET `status`='" . 'normal' . "' WHERE `id_alat`='" . $perbaikan[0] . "'";
//echo $sql."<br>";
if (mysqli_query($conn, $sql) && mysqli_query($conn, $sql1)) {
echo "Pengembalian perbaikan alat dengan ID " . $perbaikan[0] . " dengan tanggal mulai perbaikan " . $perbaikan[2] . " berhasil dilakukan.<br>";
} else {
//echo mysqli_query($conn,$sql);
echo mysqli_error($conn) . "<br>";
echo "masuk";
exit;
}
}
} else {
echo "Tidak ada peralatan yang dikembalikan.<br>";
}
echo '<a href="../perbaikan.php"> Kembali ke halaman Perbaikan</a>';
}