netfrugal Posted March 3, 2006 Share Posted March 3, 2006 I need help with determining how to code PHP to allow me to upload my [!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--][u]tables.sql[/u][!--colorc--][/span][!--/colorc--] to my Database. I don't know if the errors lie within my php code, or if the sql file has problems. Here is the code I have so far:[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?php[!--colorc--][/span][!--/colorc--][!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]$dbhost ='localhost';$dbuser = 'root';$dbpass = 'password';$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to the mysql db');$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');mysql_select_db($dbname);[!--colorc--][/span][!--/colorc--][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--] ?>[!--colorc--][/span][!--/colorc--]<html><head><title>Inserting Tables to MySQL with PHP</title></head>[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?php[!--colorc--][/span][!--/colorc--][!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]mysql_create_db('TESTING-DATABASE'); // creates the databasemysql_select_db('TESTING-DATABASE') or die('Cannot select database'); $queryFile = 'tables.sql';$fp = fopen($queryFile, 'r');$query = fread($fp, filesize($queryFile));fclose($fp);$result = mysql_query($query);[!--colorc--][/span][!--/colorc--][!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]?>[!--colorc--][/span][!--/colorc--]<body></body></html>[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]<?php[!--colorc--][/span][!--/colorc--] [!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]mysql_close($conn);[!--colorc--][/span][!--/colorc--] [!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]?>[!--colorc--][/span][!--/colorc--][!--sizec--][/span][!--/sizec--]So far I can only create the Database, but the file is not uploaded. I know my code may have problems, but I can't find where. Below is what I wanted to upload:[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--][!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]CREATE TABLE `002_news` ( `id_news` bigint(13) NOT NULL auto_increment, `ueberschrift` varchar(250) default NULL, `kurztext` longtext, `autor` varchar(100) default NULL, `von` date default NULL, `bis` date default NULL, `langtext` longtext, `bild` varchar(30) default NULL, `weiter` enum('Y','N') NOT NULL default 'N', PRIMARY KEY (`id_news`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;[!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--]Is it possible that the ENGINE=MyISAM DEFAULT CHARSET=latin1 is the cause? Because when I take it out, the uploading works. But why would this be an issue?Help!Marc Link to comment https://forums.phpfreaks.com/topic/4029-uploading-sql-file-to-database/ Share on other sites More sharing options...
netfrugal Posted March 3, 2006 Author Share Posted March 3, 2006 I've got it working only if I delete "ENGINE+MYISAM DEFAULT CHARSET=latin1"However, I can't upload if I have the DROP TABLE IF EXISTS command in the sql:[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--][!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--][u]DROP TABLE IF EXISTS address_book;[/u]CREATE TABLE address_book ( address_book_id int NOT NULL auto_increment, customers_id int NOT NULL, entry_gender char(1) NOT NULL, entry_company varchar(32), entry_firstname varchar(32) NOT NULL, entry_lastname varchar(32) NOT NULL, entry_street_address varchar(64) NOT NULL, entry_suburb varchar(32), entry_postcode varchar(10) NOT NULL, entry_city varchar(32) NOT NULL, entry_state varchar(32), entry_country_id int DEFAULT '0' NOT NULL, entry_zone_id int DEFAULT '0' NOT NULL, PRIMARY KEY (address_book_id), KEY idx_address_book_customers_id (customers_id));[!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--]any thoughts? Link to comment https://forums.phpfreaks.com/topic/4029-uploading-sql-file-to-database/#findComment-13983 Share on other sites More sharing options...
villav Posted March 3, 2006 Share Posted March 3, 2006 Check your mysql version.maybe it needs TYPE=MyISAM.But anyway I think MyISAM is by default. Link to comment https://forums.phpfreaks.com/topic/4029-uploading-sql-file-to-database/#findComment-14003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.