Skip to content

Commit

Permalink
messi gli script php
Browse files Browse the repository at this point in the history
  • Loading branch information
lynwis committed Nov 26, 2008
1 parent 596bf58 commit b8447ac
Show file tree
Hide file tree
Showing 7 changed files with 1,195 additions and 1 deletion.
42 changes: 42 additions & 0 deletions php/import/dbmanager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

class dbManager{

var $dbName; // nome del database
var $dbHost; // nome dell'host su cui gira il database (localhost, oppure www.xyz.com)
var $dbPass; // password per il database
var $dbUser; // nome utente per la connesione al database


function dbManager(){
/* costruttore */
$this->dbHost = "localhost";
$this->dbName = "wiigesture";
$this->dbPass = "";
$this->dbUser = "root";
}

function dbConnect(){
/* funzione di connessione al database */
$db = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass)
or die("Errore di connessione al dbms sull'host ".$this->dbHost);
mysql_select_db($this->dbName, $db)
or die("Impossibile selezionare il database ".$this->dbName);
return $db;
}

function dbClose($db){
/* chiude la connessione col database */
mysql_close($db);
}

function execQuery($query, $db){
/* funzione di esecuzione query mySQL */
$result = mysql_query($query, $db)
or die("Errore nell'esecuzione della query...<br/>".mysql_error());
return $result;
}

}

?>
40 changes: 40 additions & 0 deletions php/import/import.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

include_once("dbmanager.php");

$file = $_POST['file'];
$tabella = $_POST['tabella'];

$originali = array("\n");
$sostituti = array("");

$dbMng = new dbManager();
$db = $dbMng->dbConnect();

$testo = @file($file);
$numline = count($testo);
$data = "";

for($i = 0; $i < $numline; $i++){

$line = str_replace($originali, $sostituti, $testo[$i]);

if($line != "<gesture>" && $line != "</gesture>"){

echo($line . "<br/>\n");
$data = $data . $line ."\n";



}
else if($line == "</gesture>"){
$query = "insert into ".$tabella." values('', '".$data."');";
$dbMng->execQuery($query, $db);
$data = "";
}

}

$dbMng->dbClose($db);

?>
17 changes: 17 additions & 0 deletions php/import/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head><title>Import di gesture nel database</title></head>

<body>

<form action="import.php" method="post">
<input type="text" name="file"/>&nbsp;File dati<br/>
<input type="text" name="tabella"/>&nbsp;Nome tabella MySQL<br/>
<input type="submit" value="Invia"/>
<input type="reset" value="Cancella"/>
</form>

<p>File nella cartella:</p>

</body>

</html>
Loading

0 comments on commit b8447ac

Please sign in to comment.