i have this php function to read my dbinfo out of a textfile on my pc:
function loaddb(){
$fh = fopen('dta.txt','r');
$line = fgets($fh);
$_SESSION['dbname']=$line;
$line = fgets($fh);
$_SESSION['dbuser']=$line;
$line = fgets($fh);
$_SESSION['dbpass']=$line;
$line = fgets($fh);
$_SESSION['server']=$line;
fclose($fh);
};
and this code works. but when it returns my code into my session var i see it has added extra line breaks in the actual variable, so the result when i connect is
Warning: mysql_connect(): Access denied for user 'root
'@'localhost' (using password: YES) in C:\Users\Jacques\Dropbox\Jacques\Web\Code.php on line 37 Could not connect: Access denied for user 'root
'@'localhost' (using password: YES)
how can i fix this. i have tried replacing all character return and spaces but it doesnt help
this is the text in my textfile
dbname
root
password
localhost:3306
trim()
them, or usefile()
to read the file into an array, and set the flag to discard newlines. – user1864610