(PHP 4, PHP 5)
mysql_create_db — Create a MySQL database
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:
mysql_create_db() attempts to create a new database on the server associated with the specified link identifier.
database_nameThe name of the database being created.
link_identifierLa 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.
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
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.