There are several ways to do this, but I do it the way I want. For MySQL with port 3306 in PDO. I am making $dsn line names. Now I am calling a new PDO with $db = new PDO(...) .
You need to use PDO::FETCH_OBJ when initializing the database connection, you can do it in various ways, but I made it a built-in array, as the fourth parameter of new PDO .
$dsn = 'mysql:dbname=test;host=localhost;port=3306'; $username = 'root'; $password = ''; $db = new PDO($dsn, $username, $password, array ( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ ));
user6364857 Jun 09 '16 at 5:43 2016-06-09 05:43
source share