Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou usando um sistema MVC para criar uma aplicação, e uma das funções do sistema é criar um novo banco de dados. Porém, não sei como faço para escolher a collation e nem cria nenhuma database nova.
Controller:
<?php
/**
* Class Home
*
* Please note:
* Don't use the same name for class and method, as this might trigger an (unintended) __construct of the class.
* This is really weird behaviour, but documented here: http://php.net/manual/en/language.oop5.decon.php
*
*/
class Home extends Controller
{
/**
* PAGE: index
* This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
*/
public function index()
{
// load views
require APP . 'view/_templates/header.php';
require APP . 'view/home/index.php';
require APP . 'view/_templates/footer.php';
}
public function addDatabase()
{
// if we have POST data to create a new song entry
if (isset($_POST["submit_add_database"])) {
// do addSong() in model/model.php
$this->model->addDatabase($_POST["name"], $_POST["collation"]);
}
// where to go after song has been added
header('location: ' . URL . 'home/index');
}
}...
public function addDatabase($name, $collation)
{
$sql = "CREATE DATABASE :name;";
$query = $this->db->prepare($sql);
$parameters = array(':name' => $name, ':collation' => $collation);
// useful for debugging: you can see the SQL behind above construction by using:
// echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit();
$query->execute($parameters);
} <form action="<?php echo URL; ?>home/adddatabase" method="POST">
<div class="row">
<div class="input-field col s6">
<input id="first_name" name="name" type="text" class="validate">
<label for="first_name">Database Name</label>
</div>
<div class="input-field col s6">
<select class="browser-default" name="collation">
<option value="0">Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
</div>
<div class="right database-submit">
<button class="btn waves-effect waves-light red lighten-3" type="submit" name="submit_add_database" value="Submit">
Create Now<i class="mdi-content-send right"></i>
</button>
</div>
</form>
...Carregando comentários...