1

I have configured server. At last I am getting this issue to make connection.

This is New Linux server as per http://157.245.105.194/test.php

Let me know what is wrong in the code given at : https://docs.google.com/document/d/1M0iqC4_5kGQVgR6aKhKFAwxbpwTOyYN7PyEgjBfL3mQ/edit?usp=sharing

At http://157.245.105.194/styleogram/fs/site/wwwroot/public/

we are getting:

===========
Notice: Undefined index: db_host in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 56

Notice: Undefined index: db_user in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 57

Notice: Undefined index: db_password in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 58

Notice: Undefined index: db_name in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 59

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)' in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php:60 
Stack trace: 
#0 [internal function]: PDO->__construct('mysql:host=;dbn...', NULL, NULL, Array) 
#1 [internal function]: Phalcon\Db\Adapter\Pdo->connect(Array) 
#2 /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php(60): Phalcon\Db\Adapter\Pdo->__construct(Array) 
#3 [internal function]: {closure}() 
#4 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault)) 
#5 [internal function]: Phalcon\Di->get('db', NULL) 
#6 [internal function]: Phalcon\Di->getShared('db') 
#7 [internal function]: Phalcon\Mvc\Model\Manager->_getConnection(Object(Article), NULL) 
#8 [internal function]: Phalcon\Mvc\Model\Manager->getReadConnection(Object(Article)) 
#9 [internal function]: Phalcon\Mvc\Model->getReadConnection() 
#10 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, Array, NU in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 60
===========
sanyassh
  • 8,100
  • 13
  • 36
  • 70
Om Vir
  • 13
  • 5

1 Answers1

1

The error you see is because your $_SERVER superglobal does not contain the elements you are looking for in your code. You can easily see this in the phpinfo() page you posted (check Apache Information section).

$connection = new MysqlAdapter(
    [
        "host"     => $_SERVER['db_host'],
        "username" => $_SERVER['db_user'],
        "password" => $_SERVER['db_password'],
        "dbname"   => $_SERVER['db_name']
    ]
];

You can remove the references to the $_SERVER array and use strings with the actual information for your installation. For instance $_SERVER['db_host'] could be localhost for you.

Once you do those replacements, check if the error persists - if not, then you have connected to your database correctly.

You can also use the Phalcon\Config object to store configuration data, such as database connection parameters as defined above, instead of setting them in the $_SERVER array.

Alternatively if you want this information to be in the $_SERVER array, then you will have to use the SetEnv in the virtualhost of your apache information.

How to use the setEnv variable in apache?

Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67