Answer the question
In order to leave comments, you need to log in
No database connection?
I want to connect to the database, but I get an error: SQLSTATE[HY000] [1193] Unknown system variable 'NAME'
. What could be the error?
database.php
<?php
class Database extends PDO{
public function __construct() {
parent::__construct(
'mysql:host='.DB_HOST.
';dbname='.DB_NAME,
DB_USER,DB_PASS,array(
PDO::MYSQL_ATTR_INIT_COMMAND =>"SET NAME 'utf8'".DB_CHAR)
);
}
}
define('DB_HOST', 'localhost');
define('DB_USER', 'admin');
define('DB_PASS', '123456');
define('DB_NAME', 'test');
define('DB_CHAR', 'utf8');
Answer the question
In order to leave comments, you need to log in
there seems to be an error here too:
it should be"SET NAMES '".DB_CHAR."'"
Judging by the text of the error, you are told that we do not understand the NAME variable. I'm not the biggest expert in MySQL and PDO in particular, but I think you should write 'SET NAMES utf8'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question