I am just trying to config my Laravel new project, I am working on xampp localhost. When I tried to run my first db insert this error appears "Fatal error: Class 'DB' not found in C:\\xampp\\htdocs\\boh\\index.php on line 48"
here is my database.php
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'boh',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
and here the short script:
<?php
DB::select('INSERT INTO `boh` VALUES name="John"');
?>
Here is an example of how you to set up a basic controller, route and your SQL query.
app/HTTP/Controllers/TestController.php
<?php namespace App\Http\Controllers;
use DB;
class TestController extends Controller {
public function getInsert()
{
DB::table('boh')->insert(
['name' => 'john']
);
}
}
app/HTTP/routes.php
<?php
Route::get('insert-test', 'TestController@getInsert');
Navigate to yourdomain.com/insert-test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.