Farrah Fawcett walks into heaven and is given one wish. She asks for all the children to be safe. God kills Michael Jackson.
*ba-dum-tchh*
Today's my mom's birthday!
6-25-09
entertainment | Thursday, June 25, 2009
Importing XML to MySQL Database: A little PHP script
I backed up my database using myphpadmin by exporting to XML. Thought it would be dandy. Was wrong, because to load back to phpmyadmin, I have to have it in SQL format. Original database was no longer available. Thought I was in some deep shit, even though some people say you can "easily" write a PHP script to get it back. Which is true, kind of. You'd think, that with the number of people making this mistake, there'd be scripts out there available already for this.
Well, here's my little contribution.
Use when your XML file looks like this:<database>
<tablename>
<id>1</id>
<name>George</name>
<type>fish</type>
</tablename>
<tablename>
<id>3</id>
<name>Renee</name>
<type>apple</type>
</tablename>
</database>
Here's a start to your script to load your table back in:$table = simplexml_load_file("backup.xml");
foreach( $table->children() as $entry )
{
$query1 = "INSERT INTO mytable ( ";
$query2 = " ) VALUES( ";
foreach( $entry->children() as $info )
{
$query1 .= $info->getName() . ", ";
$query2 .= "\"" . addslashes($info) . "\", ";
}
// kill trailing commas and form into full query
$query = substr( $query1, 0, -2 ) . substr( $query2, 0, -2 ) . " )";
mysql_query( $query ) or die( mysql_error() );
}
Notes
- I used PHP's SimpleXML. You need to be using PHP 5 for this to work.
- This only imports one table.
- Probably not the most memory efficient; for very large XML files this will probably time out.
- I started writing this post and never completed it, but I saw it again today (7/19/09) and figured I might as well post... I've still got a thing or two to learn about prompt documentation.
Excavating Old Blog Posts
meta, my websites, software | Tuesday, June 23, 2009
I actually really miss my old blog.nuggit.nu. It was poorly designed and poorly coded, yet it's utter simplicity and homeyness was irresistible to me, like a brand new cheap notepad just begging to be written in, absolutely anything. I love when I get that feeling from paper or software. It really nourishes inspiration. So I posted there pretty often. It didn't get too many visitors, but my faithful sister read it once in a while, :) so at least that pushed me to have just enough of a quality standard when posting. I loved it.
That ended when I moved to college. The server was taken down to be set in the dorm room (never to be used again, really, except to get info off of). At least I got the blog database information off before taking out the hard drive to try to house it in a different computer (which didn't work, so that one is now sitting dead on my desk). The problem was, I exported it in XML format. I figured XML was compatible with anything and everything. Right? The important thing was, last I saw, phpmyadmin could take XML to import data.
Ahahaha.
Preparing to upload the XML file to the myphpadmin that nuggit.nu currently uses, I D:'d at SQL being the only file format option to import with. I even booted into Linux to try to import with myphpadmin on there, but it was the same. What happened?! I clearly remember back in the day, having to use XML to import to phpmyadmin... as I Googled this problem, it gradually settled that I probably remembered the complete opposite thing. I probably tried XML first because it was familiar, then had to use SQL. Everywhere I looked recommended SQL for backups.
What a pain in the ass. There were many others that made the same mistake as I, but nobody really had a solution. Of course there were several possible ways to go with it. I could learn MySQL's command line interface, and use ExtractData() in some way. If I knew "a bit of PHP" someone said I could "easily" write a script to read data from the XML file. Yeah, right. I saw that more than a few times, yet people would never give a starting pointer to work from. It is not easy from where I'm standing. I hate when they're so vague.
...it was not til I Googled it while writing this blog post that I found the SimpleXML extension for PHP that does seem to make it quite simple to get data.
I'm going to work on this. I will get my old site back up, at least partially.
Pantsless Hero
It was early afternoon but I'd been getting up late so that was my breakfast time. Whatever. I was coming back from the school cafeteria, and I took a path through the large courtyard of the dormitories. Many people were hanging out here, scattered in small groups among grass, trees, and columns. I was not wearing pants. I pulled my shirt down to cover my underwear and felt glad I was wearing one of those extra long shirts. I hoped no one would notice. Nobody would notice. I'm one of those girls that wear super short shorts that you can't even see because the shirt covers the whole thing, right? I sauntered through slowly, gliding by, to not call any attention to myself, but looked around at all the groups. I passed a large group of guys, many of whom were in my major, so I recognized them. I think I caught one of their eyes but I turned away quickly and held my shirt down. I saw another sprinkle of people running from the side opening of the courtyard through the grass, falling and laughing.
There were many others coming back from getting food or going out to get food, so there was a bustling of people I had to get through to get to the right entrance. I saw, in annoyance, that the normal one was closed off for some reason. The fire exit stairway was open instead, so we moved up that. Only girls were coming up this side of the building. Which might have served as somewhat of a relief, but I felt none at all as I realized that not only was I pantsless, I was not wearing underwear either. My shirt was not long enough to shield me as I walked up the stairs. Everyone coming up behind me... they would not miss it...
We reached the top of the stairs where a sign instructed us to wait. Apparently it was some sort of dorm event. A girl spoke up. "Why are you... not wearing pants?" She made a face. All the girls were looking at me strangely, and I thought of something to say, because honestly I didn't have a good reason. There was a long, awkward minute while I had nothing to say and couldn't say anything anyway because there was a huge chunk of ice in my mouth that I couldn't melt fast enough. A different girl raised her brows and turned to her friend. "Okaaay? I guess that's a good reason too?" Her grimace broke into a giggle. I finally thought of a cop out statement and I knew I needed to speak, now, so I spit the ice out into my hand. "I dunno. I dust woge up dith way." Dammit there was still some ice in my mouth. I found a garbage can and spit the rest of it out. "Like when I woke up I was in the courtyard and I was like this." The girls looked incredulous. I know, I know; it didn't make any sense.
However, something clicked in my mind as I thought of what I said: "when I woke up." Wasn't this a really common dream scenario? Heck yeah it is! I used to study dream symbolism. This kind of dream simply indicated your feeling of vulnerability in every day life or something. I knew now that I could have all their attention when I explained. But instead of telling all the fake girls sneering at me (they were quite literally fake) I excitedly turned to a rather ugly short and stout girl standing next to me and grabbed up her hands. "No no, guess what!" I exclaimed. "I just 'woke up' this way, and I'm not wearing pants. Doesn't this all make sense?" I looked into her homely face as it clicked in her mind as well. "Yes! Wow, this makes complete sense!"
She beamed at me and I turned around and opened the door out into the halls where the event was preparing. There was a row of cheerleaders and other event coordinators creating an archway of shaking pom poms and they were all cheering. For me. They were happy that I figured this out. I ran through them and turned the corner to another archway of cheerleaders all beaming and cheering at me, and I thought to myself, "This is ridiculous." I suppose this was better than the alternative--to have them stone silent and staring at me as I streaked past. So I just ignored it. I turned a few more corners taking the shortest path to my room. I found to my relief there were no more cheering people. However, pom pom batons hung on people's doorknobs in preparation for the event. I picked some up and pretended to be a cheerleader as I ran towards my door at the end of the hall. I laughed and threw them aside. In one leap, I grabbed my doorknob, opened it (to my relief it was unlocked), swung myself in, and closed it. Badass. Ninja. Yeahhh.
I was safe now, even though this room was dark, musty, and not unpacked enough to feel homey yet. I went to my bed which was piled high with junk, and as I laid my head down on a portfolio box I realized I was about four assignments behind in C++ programming. They were large assignments and were due today. I thought about how I just wasn't doing well in my classes overall. I barely spoke in my social studies class, which... normally I would, but it was so early in the morning I usually keep my mouth shut around that time and half-sleep and doodle my way through the class. My teachers did not like me. Shouldn't I start programming? A glimmer of hope and motivation was stamped out as I thought, what's the point... I'm already too behind. I fell asleep and proceeded to live inside another dream.
In Celebration
beauty, meta, photographs | Tuesday, June 16, 2009
I changed the layout of my blog so that the content has more than 400px of width to squeeze into. In celebration of this, I will clog up visitors' bandwidth by posting a selected handful of photographs. They are all wider than 400px. This is also a celebration of June, I guess, because these are all photos I've taken in the first half of the year 2009.
Not in any particular order.
Thank you.
Feel free to save/repost as you wish, though I'd appreciate a link; all people depicted in these photographs belong to their respective selves, etc etc.
Nothing But Sunshine
I had a fairly crappy day. Vector Calc final. Felt like KILLING A FEW UNFORTUNATE BITCHES. Things got better mostly while I was sitting alone in my room, surfing and listening... but sometimes I'm so worn out that I don't know what I want to hear. Soothing electropop? Rude french house? Psychedelic goa? Brutal industrial noise? Or... hip hop?
At a pause in the music I remembered a sampling from one of Atmosphere's songs, so I located it and put the whole Atmosphere collection on shuffle. It's relatively rare when I choose to just listen to rap but when I do, I enjoy it. I must say, Atmosphere is my favorite rapper. His style always tends to put me in a good place, and his lyrics always tend to make me smile. I can think of more than a few quotes I'd love to share from his songs, but today one song stood out for me: "Nothing But Sunshine". I've only heard this song once or twice before--I admit, I don't regularly listen to everything I have by him--but when this came on I recognized it immediately. The friendly lo-fi melody on piano seeming to drip dust and yellow sun, and of course the untiring chorus:
...it's nothing but sunshine. It's all sunshine, it's nothing but sunshine. It's all sunshine, it's nothing but sunshine.
I looked up the lyrics and actually learned some things about Slug. He's not a bad storyteller either.
First verse:
Now when my mother died I had to take it in stride
There ain't no room for pride in watching your father cry
And dad made it until maybe a year later
When they found his suicide inside of a grain elevator
Got over it, I had no other offers or options
Thought about whether or not mom and pop was watching
Never bothered with caution, no time for fear
Saw my folks carry fear for most my early years
And I learned from it, turned numb and ignored the storm
A burning sun waiting for the world to plummet
Finished growing up under my uncle's roof
He taught me how to count all the way up to 100 proof
From watching him I learned how to gather nourishment
Living off the different women that he had to nurture him
And on the surface I became a normal pre-teen
More afraid of nuclear war than snake bites and bee stings
My best friend was my TV
Game shows and cartoons substituted for puppies, rainbows, and balloons
Now here I am, the shy type, and I think I'm doing alright
Considering what it was like living my life
How's that for some fresh optimism?
Atmosphere does this thing in a few of his best songs where near the end he throws in a few short lines, and repeats them as the song is drawing to a close. It's like the dessert at the end of a good meal. He does it in "Godlovesugly". He does it in "Smart Went Crazy". And he does it in "Nothing But Sunshine".
And I'm gonna be alright, and you gonna be alright,
You ain't gotta hold my hand, just walk with me tonight
Slug has this gift of telling me exactly what I need to hear.[/fangirl]
As gloomy, livid, and cold-faced as I get when I am forced to get in the math groove for finals (the reason I never made any friends in math), I'm gonna be alright, and so are you if you give me some goddamn space, but I still care about you always. Although maybe that's taking away from context. But I can think what I want.
Listen for yourself.
Youtube (full song + lyrics)