473,379 Members | 1,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Importing XML file into mysql

Hi,
I am a newbie with xml, php and MySQL.
I have an xml file that contains lists of cds. I want to import that xml file into mySQL using php. how do i do that?
thanks
Aug 7 '07 #1
3 2687
jkmyoung
2,057 Expert 2GB
This seems like a decent tutorial:
http://www.php-mysql-tutorial.com/

Firstly, you'll need to connect to the database, eg:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Connecting, selecting database
  3. $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
  4.     or die('Could not connect: ' . mysql_error());
  5. echo 'Connected successfully';
  6. mysql_select_db('my_database') or die('Could not select database');
Normally, you would then write an INSERT query eg, like so:
Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', 'phpcake', PASSWORD('mypass'), 'Y', 'Y', 'Y')";
  2.  
  3. mysql_query($query) or die('Error, insert query failed');
However, since you have XML data, either you could change the values into a comma-delimited list, or you could use other XML, SQL functions. Unfortunately, I'm not an expert on this field, so you'd have to google around.
Aug 7 '07 #2
Thanks for the help....i really appreciate it =D
I am able to display the data now.
data is purged out in a few line.
Is there a posibility of displaying the data in a table form?
Im trying to manipulate the codes to do so....but instead of havin it work or evoking errors.... the page will come out blank...So far i have done this:

<?
if(isset($_GET['id']))
{
include 'config.php';
include 'opendb.php';

$id = $_GET['id'];
$query = "SELECT name, type, size, content FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
// list($name, $type, $size, $content) = mysql_fetch_array($result);
$list= mysql_fetch_array($result);
while ($list = mysql_fetch_array($result)) {
$field1=$content["field1"];
$field2=$content["field2"];
$field2=$content["field3"];
$field2=$content["field4"];
$field2=$content["field5"];
$field2=$content["field6"];

// display recordset data
echo "<table>";
echo "<tr>";
echo "<td>Field1 Name =</td>";
echo "<td>$field1</td>";
echo "</tr><tr>";
echo "<td>Field2 Name =</td>";
echo "<td>$field2</td>";
echo "</tr>";
echo "<td>Field3 Name =</td>";
echo "<td>$field3</td>";
echo "</tr><tr>";
echo "<td>Field4Name =</td>";
echo "<td>$field4</td>";
echo "</tr><tr>";
echo "<td>Field5 Name =</td>";
echo "<td>$field5</td>";
echo "</tr><tr>";
echo "<td>Field6 Name =</td>";
echo "<td>$field6</td>";
echo "</tr><tr>";
echo "</table>";
}


//header("Content-Disposition: attachment; filename=$name");
//header("Content-length: $size");
//header("Content-type: $type");
// echo $content;

// include 'closedb.php';
exit;
}

?>
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
include 'config.php';
include 'opendb.php';

$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br>
<?
}
}
//include 'closedb.php';
?>
</body>
</html>


Looking forward for the experts point ...thanks
Aug 8 '07 #3
jkmyoung
2,057 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. $list= mysql_fetch_array($result);
  2. while ($list = mysql_fetch_array($result)) { 
  3. $field1=$content["field1"];
  4. $field2=$content["field2"];
  5. $field2=$content["field3"];
  6. $field2=$content["field4"];
  7. $field2=$content["field5"];
  8. $field2=$content["field6"];
Here, you're retrieving each row to $list. However, you're trying to get the fields from $content. Change $content to $list, or vice versa.

Also note that you're not outputting the first row of data with this, so get rid of that top line.
Aug 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andreas Emmert | last post by:
Hi there, I'm trying to import a csv file into my MySQL database. Unfortunately the number format for the price column is formatted in German style, i.e. XX,XX (decimals separated by comma not...
0
by: Campbell's List | last post by:
Hi, I'm completely new to MySql and need help importing tables from Access or Dbase. I am using Dreamweaver MX to create a data-driven web site. With the VPS hosting plan we're on, our remote...
2
by: steve | last post by:
Hi, I have researched but have not found a good solution to this problem. I am importing large amounts of data (over 50 Meg) into a new mysql db that I set up. I use >mysql dbname <...
1
by: steve | last post by:
Hi, I have a 80 meg dump file created with mysqldump. I need to import it into a mysql db on Windows. On linux, I say "shell>mysql dbname < dumpfilename" But that does not work on Windows. ...
2
by: Joel | last post by:
Hi, I'm importing our DOS data base (Dataflex) to Mysql I have a table with 174,638 records that I convert into a tab delimetered Text file however, Mysql only reads 87,035! I checked the text...
5
by: Vik Rubenfeld | last post by:
Is there a way to import an MS Access database .mdb file into MySQL running locally on a Mac? Thanks in advance to all for any info.
3
kickingthehabbit
by: kickingthehabbit | last post by:
Hi All new to all of this I just downloaded reactor server. everything works fine except Mysql - SQL import files. I am trying to import file createdb.sql I open DB and try and import with...
0
by: bjboy2006 | last post by:
Hi All, I need some advise, pointers or ideas how I can tackle this problem of mine. I am running a front end php and backend mysql db. I could import my csv file from php to mysql db. ...
2
by: Alan M Dunsmuir | last post by:
A client has sent me a (Windows) Excel Spreadsheet (.xls) file containing a block of data he wants included as a table in a MySQL database in a (Linux-based) PHP/MySQL Web application I'm...
6
by: mirianCalin | last post by:
i am doing the programming at home and our teacher checks it in school that's why i need to export/import my database.. but i dont know how.. i've found this instruction on the net but i cant...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.