Jump to content


Photo

Uploading .sql file to database


  • Please log in to reply
2 replies to this topic

#1 netfrugal

netfrugal
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 03 March 2006 - 07:08 PM

I need help with determining how to code PHP to allow me to upload my [!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]tables.sql[!--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 database

mysql_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

#2 netfrugal

netfrugal
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 03 March 2006 - 07:51 PM

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--]DROP TABLE IF EXISTS address_book;
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?

#3 villav

villav
  • Members
  • Pip
  • Newbie
  • 3 posts
  • LocationBuffalo Grove, IL

Posted 03 March 2006 - 09:27 PM

Check your mysql version.
maybe it needs TYPE=MyISAM.
But anyway I think MyISAM is by default.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users