mysql -u database code example

Example 1: mysql community server

/* Answer to: "mysql community server" */

/*
  MySQL is an open-source relational database management system. Its
  name is a combination of "My", the name of co-founder Michael
  Widenius's daughter, and "SQL", the abbreviation for Structured
  Query Language.
  
  To download the community server application go to:
  https://dev.mysql.com/downloads/mysql/
*/

Example 2: mysqli database

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

/* Vérification de la connexion */
if (mysqli_connect_errno()) {
    printf("Échec de la connexion : %s\n", mysqli_connect_error());
    exit();
}

/* Retourne le nom de la base de données courante */
if ($result = $mysqli->query("SELECT DATABASE()")) {
    $row = $result->fetch_row();
    printf("La base de données courante est %s.\n", $row[0]);
    $result->close();
}

/* Change la base de données en "world" */
$mysqli->select_db("world");

/* Retourne le nom de la base de données courante */
if ($result = $mysqli->query("SELECT DATABASE()")) {
    $row = $result->fetch_row();
    printf("La base de données courante est %s.\n", $row[0]);
    $result->close();
}

$mysqli->close();
?>

Tags:

Php Example