/    Sign up×
Community /Pin to ProfileBookmark

How to get PHP to write PHP with PHP?

I am trying to write this into a php file as a dynamic site install script?

How can i get the fwrite to write the php as code into the php file?

[code=php]

$config <<<HTML
<?php
$dbh = mysql_connect (‘localhost’,
‘”.$dbuserame.”‘,
‘”.$dbpassword.”‘)
or die(‘I cannot connect to the database because: ‘ . mysql_error());

mysql_select_db(‘”.$dbdatabase.”‘);

?>
HTML;

//Comments are for girls
$filename = “connection.php”;
if(chmod($filename, 0777)){}
$create = fopen($filename, ‘w+’) or die(“Can’t create the configeration file”);
fwrite($create,$config);
fclose($create);
if(chmod($filename, 0644)){}

[/code]

Yet that doesnt seam to work ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehMar 22.2006 — Your trouble is here:[code=php]

$config <<<HTML
<?php
$dbh = mysql_connect ('localhost',
'".$dbuserame."',
'".$dbpassword."')
or die('I cannot connect to the database because: ' . mysql_error());

mysql_select_db('".$dbdatabase."');

?>
HTML;


[/code]
[/QUOTE]
Try this instead:[code=php]$config = <<<HTML
<?php
$dbh = mysql_connect ('localhost',
'{$dbuserame}',
'{$dbpassword}')
or die('I cannot connect to the database because: ' . mysql_error());

mysql_select_db('{$dbdatabase}');

?>
HTML;

[/code]
Copy linkTweet thisAlerts:
@bokehMar 22.2006 — By the way should [I]$dbuserame[/I] be [I]$dbusername[/I]
Copy linkTweet thisAlerts:
@SheldonauthorMar 22.2006 — ooooh your good! Thanks Bokeh
Copy linkTweet thisAlerts:
@72newbieMar 22.2006 — Hmm....
×

Success!

Help @Sheldon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...