PHP-SQL

Sep 3, 2020 PHP SQL

<p> Output in learning <br>

There may be some mistakes … </ p>

Connect to database

$ host ='';
$ username ='mysql username';
$ password ='mysql password';
$ dbname ='';
$ charset ='utf8';

// DSN string for mysql
$ dsn ='mysql: dbname ='. $ dbname.'; Host ='. $ Host.'; charset ='. $ charset;

try {
        $ dbh = new PDO ($ dsn, $ username, $ password, array (PDO :: MYSQL_ATTR_INIT_COMMAND =>'SET NAMES utf8mb4'));
        $ dbh-> setAttribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);
        $ dbh-> setAttribute (PDO :: ATTR_EMULATE_PREPARES, false);
      
                            Do the processing

  } catch (PDOException $ e) {
      echo'An error occurred during database processing. Reason:'. $ E-> getMessage ();
  }

Connect to DB and register data in table ```php