I am using a route to initialize a database:
[
'pattern' => 'initdb',
'action' => function() {
$db = Db::connect();
$votes = 'CREATE TABLE votes(id INT, video VARCHAR(10), rate VARCHAR(10), PRIMARY KEY (id))';
if ($db->validateTable('votes')) { // if table exists
$db->dropTable('votes'); // drop it
$db->query($votes); // create a blank one
} else {
$db->query($votes); // if it doens't exist, create it
}
return 'database initialized';
}
]
Upon visiting this route, the first time I get the error “array_search() expects parameter 2 to be array, string given”, and if I visit it again, it works as epxected. What am I doing wrong?