Stergerea unei baze de date

postat acum 4 ani de Stefanescu Mihai in categorie PHP

Daca nu mai aveti nevoie de o baza de date puteti sa o stergeti. Ca si in cazul anterior, putem folosi functia query pentru a sterge o baza de date.

<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'parola';
$conn = new mysqli($dbhost, $dbuser, $dbpass);
if(! $conn ){
  die('Nu ma pot conecta: ' . $conn->error());
}
$sql = 'DROP DATABASE test_mike';

$retval = $conn->query( $sql );

if(! $retval ){
  die('Nu pot sterge baza de date: ' . $conn->error());
}
echo "Baza de date stearsa.\n";
$conn->close();
?>

Atentie: Stergerea unei baze de date este periculoasa. Asigurati-va ca stergeti ce trebuie si/sau ca aveti un backup.

Stergerea unui tabel

Ca si in cazul de mai sus, putem folosi functia query() pentru a sterge un tabel.

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbdb = 'test_mike';
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbdb);
if(! $conn ){
  die('Nu ma pot conecta: ' . $conn->error());
}
$sql = 'DROP TABLE users';

$retval = $conn->query( $sql );

if(! $retval ){
  die('Nu pot sterge tabelul: ' . $conn->error());
}
echo "Tabel sters.\n";
$conn->close();
?>

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de yeezy boost 350 v2 la data de 16.05.2019
I am just commenting to make you be aware of what a useful experience my cousin's child obtained going through your web site. She picked up several things, which included what it is like to possess an incredible teaching character to have many people completely comprehend selected complex things. You really surpassed her desires. Many thanks for imparting those useful, healthy, edifying and as well as easy thoughts on your topic to Mary.
Comentariu postate de yeezy shoes la data de 17.05.2019
I would like to convey my passion for your kindness in support of individuals that should have guidance on that content. Your personal dedication to getting the message along had become quite practical and has regularly empowered folks much like me to reach their endeavors. Your warm and helpful tips and hints means a great deal to me and further more to my office workers. Thank you; from everyone of us.