Fungsi mysqli select_db() PHP – DosenIT.com

Definisi dan juga Penggunaan

Fungsi select_db() / mysqli_select_db() digunakan untuk meningkatkan database default untuk hubungan.

Syntax

Object oriented model:

$mysqli -> select_db(title)

Procedural model:

mysqli_select_db(connection, title)

Nilai Parameter

Parameter Deskripsi
connection Required. Menentukan hubungan MySQL yang pasti akan digunakan
title Required. Menentukan bagian database

Detail Teknis

Return Value: TRUE jika hasil. FALSE jika berhenti bekerja
PHP Version: 5+

Contoh – Object oriented model
Ubah database default untuk hubungan:

<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");

if ($mysqli -> connect_errno) {
  echo "Gagal Menghubungkan langsung ke MySQL: " . $mysqli -> connect_error;
  exit();
}

// Kembalikan bagian database default instan ini
if ($outcome = $mysqli -> question("SELECT DATABASE()")) {
  $row = $outcome -> fetch_row();
  echo "Default database is " . $row[0];
  $outcome -> shut();
}

// Ganti db langsung ke db "take a look at" 
$mysqli -> select_db("take a look at");

// Kembalikan bagian database default instan ini
if ($outcome = $mysqli -> question("SELECT DATABASE()")) {
  $row = $outcome -> fetch_row();
  echo "Default database is " . $row[0];
  $outcome -> shut();
}

$mysqli -> shut();
?>

Contoh – Procedural model
Ubah database default untuk hubungan:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno()) {
  echo "Gagal Menghubungkan langsung ke MySQL: " . mysqli_connect_error();
  exit;
}

// Kembalikan bagian database default instan ini
if ($outcome = mysqli_query($con, "SELECT DATABASE()")) {
  $row = mysqli_fetch_row($outcome);
  echo "Default database is " . $row[0];
  mysqli_free_result($outcome);
}

// Ganti  db langsung ke db "take a look at" 
mysqli_select_db($con, "take a look at");

// Kembalikan bagian database default instan ini
if ($outcome = mysqli_query($con, "SELECT DATABASE()")) {
  $row = mysqli_fetch_row($outcome);
  echo "Default database is " . $row[0];
  mysqli_free_result($outcome);
}

// puncak hubungan
mysqli_close($con);
?>

Anda ringan menonton: Fungsi mysqli select_db() PHP – DosenIT.com

Sumber: https://taylorswift10years.com

Kategori: Teknologi

Leave a Reply