Jump to content

mysql_connect question


lukerodham

Recommended Posts

Hi, this is more of a question than asking for help so if its in the wrong section could someone please move.

 

my question is could you connect to a database by using an array that has been generated from getting contents from a file, for example...

$file_c = file_get_contents("example.txt");
$colms = explode(",",trim($file_c));

mysql_connect("$colms[0]","$colms[1]","$colms[2]") or die(mysql_error());
mysql_select_db("$colms[3]") or die(mysql_error());

 

if not how else would someone go about doing this.

Link to comment
Share on other sites

Array variables are no different than any other variable, as long as they contain what you expect.

 

What sort of problem or error did you have when you tried your code?

 

Be careful when storing database credentials in a plain text file as anyone who discovers that file or sees it if your server allows directory listings can simply browse to the file and see your database credentials.

Link to comment
Share on other sites

Yes of course.  Variables are variables and mysql_connect() simply requires variables to plug into it's parameters when it is called.  It doesn't care one bit whether or not those variables are elements in an array. 

Link to comment
Share on other sites

ive just looked at the file where the value is held and there is not whitespace in front of the value and no behind. i do have the comma there that is trimmed but thats it. could there be a problem with the file_get_contents action that i have written?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.