I’m looking for help or sample code that I can use to change an XML page to data to be uploaded to a MySQL server. Anything will help.

I forgot to add: in php, and i already have a working server.

I already know a good amount of php.

php, c++, asp, vb, … what language do you want it in?

I would definitely recommend using PHP to interface with MySQL. They actually integrate quite nicely. If you own the web server but don’t have PHP installed, there are no worries… it’s free and even runs on Windows! to connect to a MySQL database and retrieve information from it (I guess it’s a little more confusing than I thought for someone just starting out), all you have to do is something like:

// initial defines
$dbhost = 'db.host.name';
$dbusername = 'username';
$dbuserpassword = 'pass';
$default_dbname = 'default'
$default_sort_order = 'DESC';
$default_order_by = 'num';

// connect function

function db_connect() {
   global $dbhost, $dbusername, $dbuserpassword, $PHP_SELF, $default_dbname;
   $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
   if(!$link_id) {
      $MYSQL_ERRNO = 0;
      $MYSQL_ERROR = "Connection failed to the host $dbhost.";
      return 0;

//   ...
//   error handling functions here (omitted for length)
//   ...

// the actual function to connect to the database

function database_connectivity() {
  global $defaul_dbname, $default_tablename, $PHP_SELF, $view;
  global $default_sort_order, $default_order_by, $posts_per_page; 
  global $sort_order, $order_by, $cur_page;
  $link_id = db_connect($default_dbname);
  if(!link_id) error_message(sql_error());
  $order_by_str = "ORDER BY '$default_order_by'";
  $sort_order_str = "DESC";
 $query = "SELECT * FROM `$default_tablename` 
  $order_by_str $sort_order_str;
  while($query_data = mysql_fetch_array($result)) {
    $num = $query_data"num"];
    $date = $query_data"date"];
    $text = $query_data"text"];

    echo (" ... ");


If you have any questions regarding the language, the code, or life, the universe and everything, feel free to contact me.

#               Functions:               #
#              DB Functions              #

function dbcon() { #Obviously, this connects to the SQL server, using the values from qzconfig.php
 global $dbhost, $dbuser, $dbpass, $db;
 $sql_server = @mysql_connect($dbhost,$dbuser,$dbpass)
  or die("<b>Fatal Error:</b><br /><b>MYSQL:</b> Unable to connect to mySQL server.");

   or die("<b>Fatal Error:</b><br /><b>MYSQL:</b> Unable to query mySQL server.");

function dbquery($sql) { #For custom queries
 global $result, $querycount;
 	$result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());

Is what I use to make DB connections and queries. Its a tad shorter than Steve’s but you are shorting yourself of the ordering and such. (Which IMO is actually better, because I’d rather be able to control the exact DB Query… but thats just me)

Call dbcon(); then dbquery(‘SQL QUERY’);

I also have an additional config file to insert the variables, but I don’t think you want my password.:rolleyes:

i know if i didn’t know php that well those code snippets would confuse the crap out of me haha…

the second one is a little easier to grasp…look around on a lot of open source sites (pscode.com, sourceforge.net even…) they can provide step by step tutorials on this subject.


my assumption was that he knew PHP already. sorry.

go here:

for an explanation of using PHP/MySQL. You might want to read the rest of the tutorial… but this is what i found truly pertinent.

If you don’t already, try getting PHP My Admin ( http://www.phpmyadmin.net/ )

and, i’m not sure what you are asking. People have provided examples of PHP generating say, HTML from MySQL, but if you are trying to take XML and parse it, it really depends on what you are trying to do…


They provide anything you’d wanna know about learning XML. (and other w3.org stuff)

I know a lot of php. What I am trying to do is take data from a XML page, and insert it into a MySQL db. I am also hoping to do this useing php.

what kind of data?

can i see the XML page?

*Originally posted by apk *
** What I am trying to do is take data from a XML page, and insert it into a MySQL db. I am also hoping to do this useing php. **

I assume you know how to insert into mysql and are looking for how to parse the XML.

Check out the two links at the very bottom of this page: http://www.chiefdelphi.com/forums/misc.php?s=&action=xml

One is an example on how to parse the XML that runs the ‘last 10 threads on my page’ thing from chiefdelphi. The other is the manual page for parsing XML with php.

Hope that helps a bit.