i have ubuntu 14.04 lts. set apache, phpmyadmin , mysql. can access databases through localhost/phpmyadmin using set password , root username. have put link inside /etc/apache2/sites-enabled links original .conf file of website located in /etc/apache2/sites-available. , has these lines (mypage.conf
php_value mysql.default.user root php_value mysql.default.password mypass php_value mysql.default.host localhost when try connect database using in index.php works prettily:
mysql_connect('localhost', 'root', 'mypass') or die(mysql_error()); but when try connect database using below:
mysql_connect(ini_get("mysql.default.host"), ini_get("mysql.default.user"), ini_get("mysql.default.password")) or die(mysql_error()); in return posts error message page , doesn't execute rest of code:
access denied user ''@'localhost' (using password: no) as can understand this, gets default values ''. must doing wrong .conf file. can me it?
as stated @vanitas, changed connection style pdo instead of mysql. here's
connection.php
<?php define('db_host', 'localhost'); define('db_name', 'mydb'); define('db_user', 'usr'); define('db_pass', 'pss'); try{ $db = new pdo('mysql:host='.db_host.'; dbname='.db_name, db_user, db_pass); }catch(pdoexception $exeption){ echo $exeption->getmessage(). '<br/>'; die(); } ?> and retrive using
require_once('../../0n/connection.php'); it's outside of web directory. so, it's safe. suppose. , it's working prettily.
Comments
Post a Comment