ahojte,
prepacte za nevistizny predmet ale...
mam priklad z knizky prva kapitola s databazami. najprv som si odpisal cely priklad.
je to rovnako ako v knizke tak neviem v com je problem mam ubuntu 9.04 a lamp server.
takze subor 1:
Kód:
<?php
$spojit = mysql_connect( "localhost", "*****", "*****" ) or
die( "skontrolujte pripojenie k serveru" );
$tvorba = mysql_query( "CREATE DATABASE IF NOT EXISTS moviesite" ) or
die( mysql_error() );
mysql_select_db( "moviesite" );
$filmy = "CREATE TABLE movie (
movie_id int( 11 ) NOT NULL auto_increment,
movie_name varchar( 255 ) NOT NULL,
movie_type tinyint( 2 ) NOT NULL default 0,
movie_year int( 4 ) NOT NULL default 0,
movie_leadactor int( 11 ) NOT NULL default 0,
movie_director int( 11 ) NOT NULL default 0,
PRIMARY KEY ( movie_id ),
KEY movie_type ( movie_type, movie_year )
)";
$vysledky = mysql_query( $filmy ) or
die( mysql_error() );
$typyfilmov = "CREATE TABLE movietype (
movietype_id int( 11 ) NOT NULL auto_increment,
movietype_label varchar( 100 ) NOT NULL,
PRIMARY KEY ( movietype_id ),
)";
$vysledky = mysql_query( $typyfilmov ) or
die( mysql_error() );
$ludia = "CREATE TABLE people (
people_id int( 11 ) NOT NULL auto_increment,
people_fullname varchar( 255 ) NOT NULL,
people_isactor tinyint( 1 ) NOT NULL default 0,
people_isdirector tinyint( 1 ) NOT NULL default 0,
PRIMARY KEY ( people_id ),
)";
$vysledky = mysql_query( $ludia ) or
die( mysql_error() );
echo "databaza bola uspesne vytvorena !";
?>
ked to spustim 1x tak vypise :
Kód:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 5
viackrat uz len :
Kód:
Table 'movie' already exists
chcem vediet co znamena to prve.
potom mam hned nato dalsi subor ktory pustam zdy az po tom prvom samozrejme:
Kód:
<?php
$spojenie = mysql_connect( "localhost", "*****", "*****" ) or
die( "skontrolujte prosim pripojenie k serveru" );
mysql_select_db( "qwerty" );
$vlozit = "INSERT INTO movie ( movie_id, movie_name, movie_type, " .
"movie_year, movie_leadactor, movie_director ) " .
"VALUES ( 1, 'Bozsky Bruce', 5, 2003, 1, 2 ), " .
"( 2, 'Malery pana Sikuly', 5, 1999, 5, 6 ), " .
"( 3, 'Grand Canyon', 2, 1991, 4, 3 )";
$vysledky = mysql_query( $vlozit ) or
die( mysql_error() );
$typ = "INSERT INTO movietype ( movietype_id, movietype_label ) " .
"VALUES ( 1, 'sci Fi' ), " .
"( 2, 'drama' ), " .
"( 3, 'dobrodruzny' ), " .
"( 4, 'vojensky' ), " .
"( 5, 'komedia' ), " .
"( 6, 'horor' ), " .
"( 7, 'akcny' ), " .
"( 8, 'detsky' )" ;
$vysledky = mysql_query( $typ ) or
die( mysql_error() );
$ludia = "INSERT INTO people ( people_id, people_fullname, " .
"people_isactor , people_isdirector ) " .
"VALUES ( 1, 'Jim Carrey', 1, 0 ), " .
"( 2, 'Tom Shadyac', 0, 1, ), " .
"( 3, 'Lawrence Kasdan', 0, 1 ), " .
"( 4, 'Kevin Kline', 1, 0 ), " .
"( 5, 'Ron Livingston', 1, 0 ), " .
"( 6, 'Mike Judge', 0, 1 )";
$vysledky = mysql_query( $ludia ) or
die( mysql_error() );
echo "vlozenie dat prebehlo uspesne";
?>
pritom vypise zas :
Kód:
Duplicate entry '1' for key 1
nikde nevydim chybu tak co su tie hlasky ? a preco to nejde ?