KBD

Keith Devens .com

Sunday, November 23, 2008 Flag waving
*What in our history together makes you think I'm capable of something like that?* – Owen Wilson's character in Shanghai Knights

Tag: MySQL

Parents:

Daily link icon Thursday, January 18, 2007

  1. SQLyog is an open source (here's the project on Google code) MySQL administration GUI. I just used it to reorder some fields in a table -- I've been wanting something with that feature for a while.

       (0) Tags: [MySQL, Software]

Daily link icon Saturday, February 11, 2006

  1. Epsilon-Delta: Mathematics and Computer Programming » Dissecting MySQL Fulltext Indexing (via Matt Mullenweg). To read.

       (0) Tags: [MySQL, Programming]

Daily link icon Saturday, August 27, 2005

  1. MySQL Reference Manual :: A.2.8 MySQL server has gone away. If you get that error while trying to do a large import, change the max_allowed_packet setting to something big enough to be able to cover your largest SQL statement in the import file. This is usually a problem when you export your data with MySQL's extended SQL insert format, since an entire table results in just one insert statement.

       (0) Tags: [MySQL]

Daily link icon Tuesday, March 9, 2004

Boo MySQL

I'm normalizing some database tables more than I was hoping to get away with. I would have gotten away with it too, if it wasn't for you meddling kids... er, if I didn't need the ability to rename what I was planning to make a key.

Because MySQL doesn't support subqueries (if there was ever a case of worse-is-better, it's PHP and MySQL), the following very simple query:

UPDATE Bookmark_Keywords SET Bookmark_Keyword_Id = (
   SELECT Bookmark_Keyword_Id
   FROM Bookmark_Keyword_Info
   WHERE Bookmark_Keyword_Name = Bookmark_Keyword
)

is going to require that I write procedural code to update the table. Bust.

Update: For future reference, here's the code I had to write:

<?php
$sql 
'SELECT DISTINCT Bookmark_Keyword_Info.Bookmark_Keyword_Id id, Bookmark_Keyword_Name name
   FROM Bookmark_Keyword_Info
   INNER JOIN Bookmark_Keywords ON(Bookmark_Keyword_Name = Bookmark_Keyword)
   ORDER BY Bookmark_Keyword_Name'
//reformatted to fit layout
$rs_id mysql_query($sql$conn) or die("Couldn't select your keywords: ".mysql_error());
while(
$row mysql_fetch_assoc($rs_id)){
    
$sql "UPDATE Bookmark_Keywords
        SET Bookmark_Keyword_Id = $row[id]
        WHERE Bookmark_Keyword = '$row[name]'"
// reformatted to fit layout
    
print_r($row);
    echo 
'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    
print_r($sql);
    
mysql_query($sql$conn) or die("Couldn't update your table: ".mysql_error());
    echo 
'<br>';
}
?>

Any formatting in there (print_r, echo), etc., was for me to see that the right thing was going to happen before I uncommented the mysql_query line. And of course, this is just "one-off" code... for instance, I didn't addslashes() on $row[name] because I knew none of my names had slashes or quotes in them.

November 2008
SunMonTueWedThuFriSat
 1
2345678
9101112131415
16171819202122
23242526272829
30 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

new⇒Spider solitaire

Does anyone play without using​Undo, without choosing the game​they play, a...

You Don't Even Realize: Nov 22, 5:14pm

new⇒Ubuntu Nvidia install not working for me... could use a hand

Cant change xorg.conf!

I'm not​the owner of it, don't ask me​why
but it...

I)orogon: Nov 22, 5:41am

Calif. Supreme Court to take up gay marriage ban

I would argue the point is not​definitional.  While the word​marriage is su...

Justin: Nov 20, 4:37pm

Java join function

Meh, don't have null strings in​your string arrays imo, but you're​welcome ...

Keith: Nov 19, 7:51pm

Girls, please don't get breast implants

sorry but another thing i have to​make a comment on about you​men...the men...

happynow: Nov 17, 11:36pm

Generated in about 0.148s.

(Used 10 db queries)

mobile phone