phpday 2027 - Call for Papers

mysql_create_db

(PHP 4, PHP 5)

mysql_create_db — Create a MySQL database

Avviso

Questa funzione è stata deprecata in PHP 4.3.0, ed essa e l'intera estensione MySQL originale sono state rimosse in PHP 7.0.0. Al suo posto, usare l'estensione MySQLi o PDO_MySQL, entrambe attivamente sviluppate. Vedere anche la guida MySQL: scelta dell'API. Le alternative a questa funzione includono:

Descrizione

function mysql_create_db(string $database_name, resource $link_identifier = NULL): bool

mysql_create_db() attempts to create a new database on the server associated with the specified link identifier.

Elenco dei parametri

database_name

The name of the database being created.

link_identifier

La connessione MySQL. Se l'identificativo di connessione non è specificato, viene usata l'ultima connessione aperta da mysql_connect(). Se tale connessione non viene trovata, si cercherà di crearne una come se mysql_connect() fosse stata chiamata senza argomenti. Se nessuna connessione viene trovata o stabilita, viene generato un errore di livello E_WARNING.

Valori restituiti

Restituisce true in caso di successo o false in caso di fallimento.

Esempi

Example #1 mysql_create_db() alternative example

The function mysql_create_db() is deprecated. It is preferable to use mysql_query() to issue an sql CREATE DATABASE statement instead.

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$sql = 'CREATE DATABASE my_db';
if (mysql_query($sql, $link)) {
    echo "Database my_db created successfully\n";
} else {
    echo 'Error creating database: ' . mysql_error() . "\n";
}
?>

Il precedente esempio visualizzerà qualcosa di simile a:

Database my_db created successfully

Note

Nota:

Per la compatibilità all'indietro, è possibile utilizzare il seguente sinonimo deprecato: mysql_createdb()

Nota:

This function will not be available if the MySQL extension was built against a MySQL 4.x client library.

Vedere anche:

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top