Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17877
| From | ^Bart <gabriele1NOSPAM@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Two PDO login but just one works! :\ |
| Date | 2019-04-12 16:55 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <q8q8sl$1906$1@gioia.aioe.org> (permalink) |
I'm testing on a local server new php features, this PDO is ok:
<?php
$host = 'localhost';
$db = 'mydb';
$user = 'mydb_user';
$pass = '87654321';
$charset = 'latin1';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
?>
This below doesn't work :\
<?php
session_start();
/* DATABASE CONFIGURATION */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'mydb');
define('DB_PASSWORD', '87654321');
define('DB_DATABASE', 'mydb_user');
function getDB()
{
$dbhost=DB_SERVER;
$dbuser=DB_USERNAME;
$dbpass=DB_PASSWORD;
$dbname=DB_DATABASE;
try {
$dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser,
$dbpass);
$dbConnection->exec("set names latin1");
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbConnection;
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
?>
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
Two PDO login but just one works! :\ ^Bart <gabriele1NOSPAM@hotmail.com> - 2019-04-12 16:55 +0200
Re: Two PDO login but just one works! :\ Luuk <luuk@invalid.lan> - 2019-04-12 19:04 +0200
Re: Two PDO login but just one works! :\ ^Bart <gabriele1NOSPAM@hotmail.com> - 2019-04-12 21:24 +0200
Re: Two PDO login but just one works! :\ Markus Heinz <markus.heinz@uni-dortmund.de> - 2019-04-12 21:42 +0200
Re: Two PDO login but just one works! :\ ^Bart <gabriele1NOSPAM@hotmail.com> - 2019-04-13 11:55 +0200
csiph-web