Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17877 > unrolled thread

Two PDO login but just one works! :\

Started by^Bart <gabriele1NOSPAM@hotmail.com>
First post2019-04-12 16:55 +0200
Last post2019-04-13 11:55 +0200
Articles 5 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  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

#17877 — Two PDO login but just one works! :\

From^Bart <gabriele1NOSPAM@hotmail.com>
Date2019-04-12 16:55 +0200
SubjectTwo PDO login but just one works! :\
Message-ID<q8q8sl$1906$1@gioia.aioe.org>
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();
}

}
?>

[toc] | [next] | [standalone]


#17878

FromLuuk <luuk@invalid.lan>
Date2019-04-12 19:04 +0200
Message-ID<5cb0c532$0$22343$e4fe514c@news.xs4all.nl>
In reply to#17877
On 12-4-2019 16:55, ^Bart wrote:
> 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();
> }
> 
> }
> ?>

Is there any output from this:
echo 'Connection failed: ' . $e->getMessage();
and, if, what's the output?


-- 
Luuk

[toc] | [prev] | [next] | [standalone]


#17879

From^Bart <gabriele1NOSPAM@hotmail.com>
Date2019-04-12 21:24 +0200
Message-ID<q8qokl$1hk6$1@gioia.aioe.org>
In reply to#17878
> Is there any output from this:
> echo 'Connection failed: ' . $e->getMessage();
> and, if, what's the output?

No, I don't have it but I should reset everything and start from zero! :)

[toc] | [prev] | [next] | [standalone]


#17880

FromMarkus Heinz <markus.heinz@uni-dortmund.de>
Date2019-04-12 21:42 +0200
Message-ID<20190412214250.04ed21a9@computer5>
In reply to#17877
Hello.

On Fri, 12 Apr 2019 16:55:18 +0200
^Bart <gabriele1NOSPAM@hotmail.com> wrote:

> 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';

[...]

> 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');
[...]

In the second example database username and database name are exchanged.

Regards

Markus

[toc] | [prev] | [next] | [standalone]


#17881

From^Bart <gabriele1NOSPAM@hotmail.com>
Date2019-04-13 11:55 +0200
Message-ID<q8sbmk$d6e$1@gioia.aioe.org>
In reply to#17880
>> <?php
>> session_start();
>> /* DATABASE CONFIGURATION */
>> define('DB_SERVER', 'localhost');
>> define('DB_USERNAME', 'mydb');
>> define('DB_PASSWORD', '87654321');
>> define('DB_DATABASE', 'mydb_user');
> [...]
> 
> In the second example database username and database name are exchanged.

I just changed real details! :)

^Bart

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web