kentopolis Posted January 31, 2007 Share Posted January 31, 2007 I am having trouble with this script. I am trying to create an install file that will install my database and tables. I would like the database name to and host name to be read from a text file name host.txt. The honest truth is, I don't know very much about php at all. I'm sure there is an easy answer, maybe it is just "this can't be done". But I have tried every configuration I can think of and I honestly just need some help. I can get ti to work if I manually enter the host name, as below. I also have the script working to read the file, I just can't seem to integrate the two... Here is the script as is working without reading the text file into the host names (I have not provided all of the script, i.e. the tables section, because the other part is working great...<?phpinclude 'config.php';include 'opendb.php';//begin get host name need to figure out how to install it into script$fp = @fopen("host.txt", "rb") or die("Couldn't open file");$data = fread($fp, filesize($fp));while(!feof($fp)){$data .= fgets($fp, 1024);}fclose($fp);$values = explode("\r\n", $data);echo "" . $values[0] . "puppylist";//end get hostname$query = 'CREATE DATABASE hostname_puppylist';$result = mysql_query($query);mysql_select_db('hostname_puppylist'); or die('Cannot select database, install db: puppylist dbu: puppylister');$query = $query = 'CREATE TABLE dogs2( '.....here is the section I am having trouble with...$query = 'CREATE DATABASE hostname_puppylist';$result = mysql_query($query);mysql_select_db('hostname_puppylist'); or die('Cannot select database, install db: puppylist dbu: puppylister');I want it to look like this...$query = 'CREATE DATABASE echo "" . $values[0] . "_puppylist"';$result = mysql_query($query);mysql_select_db(echo "" . $values[0] . "_puppylist"); or die('Cannot select database, install db: puppylist dbu: puppylister');....I know I've got it all wrong, is there anyone who can help me? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 31, 2007 Share Posted January 31, 2007 $query = 'CREATE DATABASE '.$values[0].'_puppylist';Take out all those echos. Quote Link to comment Share on other sites More sharing options...
KrisNz Posted January 31, 2007 Share Posted January 31, 2007 as an aside you can replace[code]$fp = @fopen("host.txt", "rb") or die("Couldn't open file");$data = fread($fp, filesize($fp));while(!feof($fp)){$data .= fgets($fp, 1024);}fclose($fp);$values = explode("\r\n", $data);[/code]with[code]$values = file("host.txt");[/code] Quote Link to comment Share on other sites More sharing options...
Hypnos Posted January 31, 2007 Share Posted January 31, 2007 EDIT: Nevermind Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.