Home>

bd.php

<
? php.
    $ db_host= "127.0.0.1"; //Specify the IP address instead of Localhost (when specifying the localhost, it is looking for an IP address)
    $ db_name= "anime";
    $ db_user= "mysql";
    $ DB_PASSWORD= "MYSQL";
    $ db= new pdo ("MySQL: Host= $ db_host; dbname= $ db_name", $ db_user, $ db_password);
    ? ≫

index.php

<
? php.
    Require_ONCE 'PLUS /BD.PHP';
    If (! MySQLI_SET_CHARSET ($ Connection, $ Charset)) {
        Print ("encoding error");
    }
? ≫

Output shape from BD

<
? php.
            $ Names= $ DB->
Prepare ("SELECT * from Names Order by Rand () Limit 1");
            $ Names->
Execute ();
            //WHILE CYCLE FOR DATA DATA
            while ($ ani= $ names->
fetch ()):
        ? ≫
    ≪
H1 Class= "H-1" >
≪
?= $ ani ['name'];? >
≪
/h1 >
    ≪
BR >
    ≪
p class= "p-1" >
≪
?= $ ani ['description'];? >
≪
/P >
    ≪
BR >
    ≪
p class= "p-2" >
 ID list: <
?= $ ani ['id'] ;? >
≪
/P >
    ≪
? php endwhile; ? ≫
  • Answer # 1

    It is not clear why you are using PDO and the encoding in MySQLI indicate.

    $ db= new pdo ("mysql: host= {$ db_host}; dbname= {$ db_name}; charset= utf8", $ db_user, $ db_password);