基本的に、switch ステートメントといくつかの関数を含むコードがあります。ブラウザから与えられたパラメータを使用して switch ステートメントに移動し、" ?step=X
" 適切な関数を選択します。
私の問題は、各関数の最後で、次の switch ステートメントに移動するように指定した場合でも、決して実行されず、ブラウザで「step = x」で選択した関数の無限ループになることです...
1 つの関数でスタックして、それらを反復しないのはなぜですか? (ステップのコードはスクリプトの最後で強調表示されます)
選択した関数のブラウザーで出力を取得します。そのため、スイッチと選択した機能に入ります...しかし、ブラウザで同じエコーステートメントを300取得するため、無限ループになります。それらを反復したり、選択した関数を終了したりすることはできません。
<?php
//DB Config File
$dbFile = 'dbconfig.php';
$username = $_GET['username'];
$password = $_GET['password'];
$server = $_GET['server'];
$dbname = $_GET['dbname'];
$step = $_GET["step"];
function createfile ($dbFile) {
//Creates File and populates it.
$fOpen = fopen($dbFile, 'w');
global $username, $password, $server, $dbname;
$fString .= "<?php\n";
$fString .= "// Database Constants\n";
$fString .= "\$DB_SERVER =" . "\"" . $server . "\";\n";
$fString .= "\$DB_USER =" . "\"" . $username . "\";\n";
$fString .= "\$DB_PASS =" . "\"" . $password . "\";\n";
$fString .= "\$DB_NAME =". "\"" . $dbname . "\";\n";
$fString .= "?>";
fwrite($fOpen, $fString);
fclose($fOpen);
return true;
}
try {
$db = new PDO ('mysql:host=' .$server.';dbname='.$dbname,$username,$password);
if ($db) { //if succesful at connecting to the DB
if (file_exists($dbFile)){
if (is_readable($dbFile) && is_writable($dbFile)){
//Creates File, populates it and redirects the user
if (createfile($dbFile)) {
echo "nelxt";
stepFunction($step);
exit ();
}
} else {
echo "The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission."; }
} else {
//Creates File, populates it and redirects the user
if (createfile($dbFile)) {
echo "next";
stepFunction($step);
exit ();
}
}
}
} catch (PDOException $e) { //Catchs error if can't connect to the db.
echo 'Connection failed: ' . $e->getMessage();
}
// Prepare SQL Statements
$IDB = $db->prepare(
"CREATE TABLE pages (
id int(11) NOT NULL auto_increment,
subject_id int(11) NOT NULL,
menu_name varchar(30) NOT NULL,
position int(3) NOT NULL,
visible tinyint(1) NOT NULL,
content text NOT NULL,
PRIMARY KEY (id)
)ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8");
$IDB2 = $db->prepare("
CREATE TABLE subjects (
id int(11) NOT NULL auto_increment,
menu_name varchar(30) NOT NULL,
position int(3) NOT NULL,
visible tinyint(1) NOT NULL,
PRIMARY KEY (id)
)ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8");
$IDB3 = $db->prepare("
CREATE TABLE users (
id int(11) NOT NULL auto_increment,
username varchar(50) NOT NULL,
hashed_password varchar(40) NOT NULL,
PRIMARY KEY (id)
)ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8");
//Set Option to True or False
if (empty ($_GET['fot']) ) {
$fOT = false;
} else { $fOT = true;
}
///////////////////////////////
// PROBLEMATIC STEP BEGINS HERE
///////////////////////////////
function createTablePages (){
global $db,$IDB;
echo "0 <br>";
stepFunction (1);
}
function createTableSubjects ($fOT){
global $db,$IDB2;
echo "1 <br>";
stepFunction (2);
}
function createTableUsers ($fOT){
global $db,$IDB3;
echo "3 <br>";
}
function stepFunction ($step,$fOT){
global $db,$IDB1,$IDB2,$step,$fOT;
switch ($step) {
case 0: echo "hola";
createTablePages ($fOT);
break;
case 1: echo "hola2";
createTableSubjects($fOT);
break;
case 2: createTableUsers ($fOT);
break;
}
}
?>