riccardo castagna - 2010-03-21 00:54:54
this is the class file name: class.word.php
<?php
class word{
var $dbHost = "localhost";
var $dbUser = "root";
var $dbPass = "";
var $dbName = "worddoc";
function insertion(){
$connect;
$db;
$create;
{
/*CONNECT TO MYSQL SERVER*/
$this->connect=mysql_connect($this->dbHost, $this->dbUser, $this->dbPass) or die ("Errore durante la connessione al server mysql");
/** CREATE A BATABASE ****/
$this->create=mysql_query("CREATE DATABASE IF NOT EXISTS ".$this->dbName." ;");
/*SELECT THE DATABASE*/
$this->dbnew=mysql_select_db($this->dbName, $this->connect) or die ("Errore durante la connessione al database $this->dbName");
echo "<br />database ".$this->dbName." created";
/*CRATE A TABLE FOR THE INSERTION */
$sql = "CREATE TABLE IF NOT EXISTS wordcont (
id int(2) NOT NULL auto_increment,
wordtext longtext NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;";
$exesql = mysql_query($sql);
$my_file = 'file.doc';//path to the word file
$handle = fopen($my_file, 'r');
$data = fread($handle,filesize($my_file));
$insert = "INSERT INTO wordcont (wordtext) VALUES ('$data');";
$exeinsert = mysql_query($insert);
$select = "SELECT * FROM `wordcont`;";
$exeselect = mysql_query($select);
$row = mysql_fetch_array($exeselect);
echo $row['wordcont'];
}
}
}
?>
and this to execute the class
<?php
include_once('class.word.php');
$ref=new word;
$ref->insertion();
?>