簡體   English   中英

如何在數據庫中輸入數據?

[英]How can I enter data in the database?

我一直試圖將數據保存在db中,但是此錯誤不斷出現:

(2/2) QueryException
SQLSTATE[HY000] [2002] Connection refused (SQL: insert into `stores` (`name`, `description`) values (El café de mi esquina , Es lindo))

這是控制器上的代碼:

   * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */



     public function store()
        {
          $nuevoLocal= new Store();


          $nuevoLocal->name="El café de mi esquina ";
          $nuevoLocal->description="Es lindo";

$nuevoLocal-> save();

 }

網絡:

 Route::get('/agregarNegocio', "storeController@store");

模型:

命名空間應用;

use Illuminate\Database\Eloquent\Model;

class store extends Model
{
    public $guarded =[];
    public $timestamps=false;

}

環境:

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=cafe

DB_USERNAME=root

DB_PASSWORD=root

數據庫名稱是cafe,它具有一個表存儲,該表存儲具有ID(主鍵),名稱和描述

如果放置var_dump($ nuevoLocal); 出口; 就在save()之前,這就是我得到的:

object(App\store)#158 (25) { ["guarded"]=> array(0) { } ["timestamps"]=> bool(false) ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(false) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(2) { ["name"]=> string(23) "El café de mi esquina " ["description"]=> string(8) "Es lindo" } ["original":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["events":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["fillable":protected]=> array(0) { } }

嘗試將DB_CONNECTION127.0.0.1切換為localhost 顯然,在Laravel中使用127.0.0.1存在一些問題。

我遇到了同樣的問題,原來端口不是標准的。 從SQL Server嘗試一下

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on', 'any', NULL, NULL, N'asc' 
GO

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM