Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 26th, 2013, 10:44 AM   #1
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
updating mysql records

ok so i have a file which i know how to add the records into the database but this file gets updated and changed constantly. this file has at least 500 records.

does anyone have some experience with this because i don't know how to accurately update the database.

thanks for your time...
origamiguy is offline   Reply With Quote
Old Aug 26th, 2013, 1:49 PM   #2
Proxi
Programmer
 
Proxi's Avatar
 
Join Date: Aug 2013
Location: Netherlands
Posts: 39
Rep Power: 0 Proxi is on a distinguished road
Re: updating mysql records

From what I've read from an tutorial:

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Proxi is offline   Reply With Quote
Old Aug 26th, 2013, 4:30 PM   #3
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: updating mysql records

first my problem is logic based. can i update something that is not there? will it add to the database if it doesn't exist? my gut says no to both. could i do something like:

update record OR add to table;

(a thought from 'connect-to-database or die();')
origamiguy is offline   Reply With Quote
Old Aug 26th, 2013, 4:32 PM   #4
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: updating mysql records

actually here is what i am currently thinking:

open xml.file
		do{
			if(preg_match('',get line from file,$matches))
			{
				a = $matches[0]; //get string
				remove first '<' char of string
				get fieldname upto '>'(but not including)
				get data between '>' and before'</' . fieldname . '>'
				add to query var
			}else
			{
				if($query variable exists)
					Try to update table in database OR add record to database
				else
					make query variable
			}
		}while(file is not EOF);

is there a better way/problems you might see?
origamiguy is offline   Reply With Quote
Old Aug 26th, 2013, 5:51 PM   #5
pritaeas
mod_pritaeas
 
Join Date: May 2009
Location: The Netherlands
Posts: 251
Rep Power: 8 pritaeas is on a distinguished road
Re: updating mysql records

Why don't you parse the XML the right way (SimpleXML or DOMDocument)?
pritaeas is offline   Reply With Quote
Old Aug 26th, 2013, 6:08 PM   #6
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: updating mysql records

never used it/ not quite sure what it does. also i like writing stuff from scratch as i tend to learn more from it.
origamiguy is offline   Reply With Quote
Old Aug 26th, 2013, 6:43 PM   #7
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: updating mysql records

this is what i have got since posting:
$file = fopen('path\file.xml', 'r');
	do{
		if(preg_match('need to fill this in',fgets($file),$matches)) // checking if each line follows the <field>data</field>/n format
		{
			$string = (string)$matches[0];
			ltrim($string,'<');
			$field = current(explode(">", $string));
			$data = current(explode("</", $string));
			$dataset .= $field . '=\'' . $data . '\',';
		}else
		{
			if(isset($dataset))
			{
				//mysqli_query($conn,"UPDATE items SET " . $dataset . "WHERE") // still unsure abou the WHERE section
				echo "UPDATE items SET " . $dataset . "WHERE<br>";
				unset($dataset);
			}else
			{
				$dataset = '';
			}
		}
	}while(!$file.EOF()); //not sure if this is correct, probably not :P

please read the comments to see what i am having trouble with
origamiguy is offline   Reply With Quote
Old Aug 27th, 2013, 5:16 AM   #8
pritaeas
mod_pritaeas
 
Join Date: May 2009
Location: The Netherlands
Posts: 251
Rep Power: 8 pritaeas is on a distinguished road
Re: updating mysql records

Checking XML syntax with a regex is bad, it can get you in a heap of trouble. Try this:

http://php.net/simplexml

http://php.net/domdocument
pritaeas is offline   Reply With Quote
Old Aug 27th, 2013, 11:35 AM   #9
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: updating mysql records

ummm... with the simplexml it shows that you have to know the fields in order to use it. i will be using this script on other xml documents and will not know if they all have the same fields. as far as the domdocument , i am still looking.
origamiguy is offline   Reply With Quote
Old Aug 27th, 2013, 2:03 PM   #10
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: updating mysql records

if i don't know the structure and the names of tags, could i use SimpleXMLIterator instead of simplexml or domdocument?
origamiguy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
awk - counting number of records and updating heading laperlenoire@gmail.com Sed and Awk 8 Dec 24th, 2012 5:43 AM
php mysql bulk records update? phantoma2 PHP 4 Feb 11th, 2012 10:10 AM
"Forbidden Page" while updating MYSQL using PHP chibib0 PHP 1 Jan 18th, 2009 1:56 AM
mysql get last 10 records in a table kruptof Other Web Development Languages 3 Jun 29th, 2007 10:23 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC