0

This is the code that worked three days ago.

I've seen answers to similar questions, but I can't solve them.

There is no error message, but it is not inserted into the database.

public static function userset()

If there is no user value in the function, you are supposed to put the value There are no values in the columns of the table.

DB.php

<?php
namespace Base\App;

class DB{
    private static $db = null;
    static function getDB(){
        if(self::$db == null){
            $options = [
                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
                \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ
            ];
            self::$db = new \PDO("mysql:host=localhost;dbname=my_house;charset=utf8mb4","root","",$options);
        }
        return self::$db;
    }

    public static function query($sql,$data=[]){
        $q = self::getDB()->prepare($sql);
        return $q->execute($data);
    }

    public static function fetch($sql,$data=[]){
        $q = self::getDB()->prepare($sql);
        $q->execute($data);
        return $q->fetch();
    }

    public static function fetchAll($sql,$data=[]){
        $q = self::getDB()->prepare($sql);
        $q->execute($data);
        return $q->fetchAll();
    }
}

Lib.php

<?php

namespace Base\App;

use Base\App\DB;

class Lib{
    public static function userset(){
        $sql = "SELECT * FROM users";
        $list = DB::fetch($sql,[]);
        if($list == false){
            $sql = "INSERT INTO users(`user_id`,`user_name`,`password`,`img`,`specialist`) VALUES(?,?,?,?,?)";
            $password = hash("sha256",1234);
            DB::query($sql,["specialist1","전문가1",$password,"specialist1.jpg",1]);
            DB::query($sql,["specialist2","전문가2",$password,"specialist2.jpg",1]);
            DB::query($sql,["specialist3","전문가3",$password,"specialist3.jpg",1]);
            DB::query($sql,["specialist4","전문가4",$password,"specialist4.jpg",1]);
        }
    }
}

public static function userset()

If there is no user value in the function, you are supposed to put the value There are no values in the columns of the table.

  • If the code stops working, you need to start debugging it. Here is a small example to give you an idea, [Debugging PHP code](https://phpdelusions.net/basic_principles_of_web_programming#debugging) – Your Common Sense Sep 25 '22 at 11:49

0 Answers0