I would like to use the DB class of laravel to execute a mysql query but none of the functions provided by Laravel are working.
None of those is working: DB::statment()
What about this code? I find it pretty usefull to use migrations & db seeding - especialy for deployment.
Schema::create('users', function($table){
$table->increments('id');
$table->string('u_username');
$table->string('u_email');
$table->string('password');
$table->datetime('u_regdate');
$table->date('u_birthday');
$table->integer('u_lastlogin');
$table->integer('u_logcout')->default(0);
$table->tinyinteger('u_level')->default(0);
$table->tinyinteger('u_language')->default(0);
$table->tinyinteger('u_status')->default(0);
$table->tinyinteger('u_gender')->default(0);
});
// Repeat this for other users as well
User::create([
'u_username' => 'admin',
'u_email' => 'admin@example.com',
'password' => Hash::make('users-password'),
'u_regdate' => date('Y-m-d H:i:s'),
'u_birthday' => '1980-01-01',
'u_lastlogin' => 0,
'u_logcout' => 0,
'u_level' => 9,
'u_language' => 0,
'u_status' => 0,
'u_gender' => 0,
]);
Drop the users table from database then try this and let me know whether it works or not:
DB::insert('CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`u_username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`u_email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`u_regdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`u_birthday` date NOT NULL DEFAULT '0000-00-00',
`u_lastlogin` int(11) NOT NULL,
`u_logcout` int(11) NOT NULL DEFAULT '0',
`u_level` tinyint(1) NOT NULL DEFAULT '0',
`u_language` tinyint(1) NOT NULL DEFAULT '0',
`u_status` tinyint(1) NOT NULL DEFAULT '0',
`u_gender` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
//and so on for all the other queries.
Executing SQL Code just like the one I provided in the question can be executed using
DB::unprepared( $code );
I hope this helps the people with the same issue i had :D
Answer found while looking through laravel issues