MySQL

Been pretty busy. I've been doing some freelance user experience work for Traction Software for the past month, so blogging here has been light. I was able to finally upgrade to Drupal 4.7, though, and the transition has been pretty smooth, with the exception of my weblinks.

As you may know, the weblink.module seems to be rather deceased or at least not upgraded to 4.7. I spent a little time thinking about how I can rescue my 813 weblink records which now only contain the bodies, but no longer link to the URL associated with the entry. So I was thinking I could use MySQL UPDATE and concatenate the node_revisions.body and weblink.weblink fields. Then I could change all weblink types to blog types.

I tried this MySQL statement:

UPDATE `node_revisions`, `weblink`
SET `node_revisions`.`body`=concat(`node_revisions`.`body`,"<br /><a href=\"",`weblink`.`weblink`,"\">Visit this page</a>")
WHERE `node_revisions`.`nid` = `weblink`.`nid`;

MySQL returns this feedback:

Query OK, 813 rows affected (0.15 sec)
Rows matched: 813 Changed: 813 Warnings: 0

So all seems OK, but when I check any weblink records, node_revisions.body hasn't been modified. I then realize that the field is a LONGTEXT and wonder if that's why nothing is happening. Can anyone provide some insight into how to get the above to work? You know that I'm an interface design and user experience guy, not a developer, so my MySQL chops are pretty light.

Any Drupal heroes out there? I created an entry for this problem on the Drupal forum, so if someone offers a response here, I'll be sure to update the entry in the forum.

I've been struggling to get a working version of Dadabik installed that allows you to select multiple values from a foreign table. I had some success with someone's patch that does this, but so far I can only get it to insert the labels for the field I want and not the id. I want the interface to show state names in the editing form, in this instance, but to insert the ID for the state name. For some reason, the Dadabik folks took the ability to select multiple values from a foreign table out of Dadabik after version 2. No idea why.

Then I found in the phpMyAdmin documentation some information about using $cfg['Servers'][$i]['relation'] and $cfg['Servers'][$i]['pmadb'] to set up foreign table relationships. This looked promising, but only allows for single value selection and only shows the ID of the foreign key for selection and not the values in another field of the foreign table. Not very useful from the data entry user's point of view.

So I'm casting about wildly for a tool that allows me to do this so I don't have to spend time trying to do it in Adodb or ezsql. Sigh. Any suggestions?

----

Incidentally, if you're wanting single value selection from a foreign table, Dadabik does it well. If you want to do it phpMyAdmin, you'll need this process and table structure for creating the relations table, which I snarfed from php-myadmin-users archive.

* set up a PMA database as described in docs

* within this database create a table following this scheme:
CREATE TABLE `PMA_relation` (
`master_db` varchar(64) NOT NULL default "",
`master_table` varchar(64) NOT NULL default "",
`master_field` varchar(64) NOT NULL default "",
`foreign_db` varchar(64) NOT NULL default "",
`foreign_table` varchar(64) NOT NULL default "",
`foreign_field` varchar(64) NOT NULL default "",
PRIMARY KEY (`master_db`, `master_table`, `master_field`),
KEY foreign_field (foreign_db, foreign_table)
) TYPE=MyISAM COMMENT="Relation table";

* put the relation table name in $cfg["Servers"][$i]["relation"]

* now as normal user open phpMyAdmin and for each table where you want
to use this feature, click "Structure/Relation view/" and choose foreign
fields.

ADOdb is a database abstraction library for PHP.

PHP Freaks article with a brief tutorial for using ADOdb.

I snarfed this from ScriptyGoddess because I thought it was a good idea to capture code snippets somewhere on this site too. This is her PHP/MySQL snippet. I have a hard time remembering this too.

$databaseName = "YOURDATABASENAME";
$dbconnection = mysql_connect("localhost", "DATABASE-USERNAME", "DATABASE-PASSWORD" or
die ('I can’t connect to the database.');
mysql_select_db($databaseName,$dbconnection);

$value = "SOMEVALUE";

$query = sprintf("SELECT FIELDNAME from TABLENAME where FIELDNAME='%s';", $value);

$result = mysql_query($query);

$totalNum = mysql_num_rows($result);

while ($row = mysql_fecth_array($result)) {
echo $row['FIELDNAME'];
}

////////OR//////

for ($i =0; $i < $totalNum; $i++) {
$row = mysql_fecth_array($result);
echo $row['FIELDNAME'];
}

CocoaMySQL 0.4 CocoaMySQL is an OS X application to manage MySQL databases (locally or over internet). It lets you add and remove databases and tables, change fields and indexes, view and filter the content of tables, add, edit and remove rows, perform custom queries and dump tables or entire databases.

update: i can't get this thing to read the mysql server on my web host. is it supposed to let you do that kind of thing?

ezSQL is quite an easy php class file for intefacing with a MySQL db.

Next to select, Update is my most often used MySQL command. I always forget that Update is what I'm looking for when I search the documentation. For some reason I always think I want Alter.

James pointed to this cool article about getting Flash to talk to PHP, I am assuming without Generator?

I wanted to do a quick proof of concept for my colleagues at work so I installed the open source trinity Apache/PHP/MySQL on my Win2k machine at work using EasyPHP. EasyPHP is an excellent application that installs all of the applications and is controlled via an icon in the task bar. It's very cool. The site is in French, but all you have to do is download the installer and run it. If you want to edit Apache's httpd.conf or php.ini, you can do it from from the system tray icon. You can also restart all the services from there. You can also do command line mysql using a dos prompt (goto: Start > Run > "cmd" ... then cd to the MySQL directory and execute "mysql"). Very cool.

I then installed WinCron and Lynx so I could use drupal. Voila. An almost cool server. Of course it's cooler if you run it on Linux or Mac OS X.