He probado añadiendo esta linea
Código PHP:
$ruta=getcwd()."/1.sql";
$db_selected = mysql_query (file_get_contents('$ruta')) or die(mysql_error());
Muchas gracias por todo, aqui os dejo como lo tengo ahora.
Código PHP:
<?php
$conecta = mysql_connect('localhost', 'root', 'admin');
if (!$conecta) {
die('No conectat : ' . mysql_error());
}
$db_selected = mysql_select_db('examens', $conecta);
if (!$db_selected) {
echo 'No es troba la base de dades',$db_selected,'<br/>';
die (mysql_error());
}
else {
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `alumnes` (`id_alumne` int(11) NOT NULL AUTO_INCREMENT, `id_usuari_fk` int(11) NOT NULL, `nom_alumne` text NOT NULL, PRIMARY KEY (`id_alumne`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `assignacio_alumnes` (`id_alumne_fk` int(11) NOT NULL,`id_materia_fk` int(11) NOT NULL, PRIMARY KEY (`id_alumne_fk`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `assignacio_professors` (`id_professor_fk` int(11) NOT NULL,`id_materia_fk` int(11) NOT NULL, PRIMARY KEY (`id_professor_fk`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `avaluacio_alumnes` (`id_avaluacio` int(11) NOT NULL AUTO_INCREMENT,`id_alumne_fk` int(11) NOT NULL,`id_examen_fk` int(11) NOT NULL,`nota_final` int(11) NOT NULL,`data` date NOT NULL,PRIMARY KEY (`id_avaluacio`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `examen` (`id_examen` int(11) NOT NULL AUTO_INCREMENT,`id_materia_fk` int(11) NOT NULL, `data_examen` date NOT NULL, PRIMARY KEY (`id_examen`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `materia` (`id_materia` int(11) NOT NULL AUTO_INCREMENT,`nom_materia` text NOT NULL, `data_inicial` date NOT NULL,`data_final` date NOT NULL,PRIMARY KEY (`id_materia`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `preguntes` (`id_pregunta` int(11) NOT NULL AUTO_INCREMENT,`id_examen_fk` int(11) NOT NULL, `pregunta` text NOT NULL,`id_resposta_correcta` int(11) NOT NULL,PRIMARY KEY (`id_pregunta`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `professors` (`id_professor` int(11) NOT NULL AUTO_INCREMENT,`id_usuari_fk` int(11) NOT NULL, `nom_professor` text NOT NULL,PRIMARY KEY (`id_professor`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `respostes` (`id_resposta` int(11) NOT NULL AUTO_INCREMENT,`id_pregunta_fk` int(11) NOT NULL, `resposta` text NOT NULL,PRIMARY KEY (`id_resposta`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `resultat_examen` (`id_resultat` int(11) NOT NULL AUTO_INCREMENT,`id_alumne_fk` int(11) NOT NULL,`id_examen_fk` int(11) NOT NULL,`id_pregunta_fk` int(11) NOT NULL,`id_resposta_fk` int(11) NOT NULL,`data` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id_resultat`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
$db_selected = mysql_query ("CREATE TABLE IF NOT EXISTS `usuaris` (`id_usuari` int(11) NOT NULL AUTO_INCREMENT,`usuari` text NOT NULL,`contrasenya` text NOT NULL,`rol` text NOT NULL,PRIMARY KEY (`id_usuari`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;") or die(mysql_error());
}
?>