Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Linking Tables Foreign key

Posted by tenerifetrekn (tenerifetrekn), 22 May 2005
Hello,

I am fairly new to web page creation and DB development.  I am using Dreamweaver mx 2004.  MySQL version is 3.23.49.  From the information I have gatherd form the online forums I am nderstanding that the MyISAM table type does not support foreign keys.  Specifically, I am trying to link data through the following scenario:  So far I have a page where sellers can register in order to list their property.  Upon registrering the seler can then login to a password protected lsiting page in order to describe the property and submit the information.  The seller registry and login work just fine as does the behavior to retrict access to the password protected listing page.  In my seller table I gave sellerID as my primary key and I also have propertyID listed to try and link the two tables together.  In the property table I have propertyID as the primary key and I also have sellerID field. The problem arises when I enter a property in the property listing page and submit the information. PropertyID appears in the property table minus the sellerID which shows 0.  How do I have the autoincrement sellerID populate in the sellerID field of the seller table so hat I might link the two together....assistance would be greatly appreciated...

Posted by tenerifetrekn (tenerifetrekn), 22 May 2005
Do I need to create a recordset with a SQL statement?

Posted by admin (Graham Ellis), 23 May 2005
MyISAM tables were enhanced with InnoDb tables, the came 4.0 and now 4.1 and we're soon to be at MySQL 5.   However, 3.23.xx remains an excellent database but some facilities were a little lacking - a "great little database" with the word little applying to some of the facilities and not the data capacity.

Suggestion -

1. insert a record into the seller table first, using a key that you define as
int not null auto_increment primary key

2. Find the key used via last_insert_id - example:

Code:
mysql> select sid from slidelib where sid = last_insert_id();
+-----+
| sid |
+-----+
| 357 |
+-----+
1 row in set (0.18 sec)

mysql>


3. Use the value returned to (manually) set the key value in the records you're in the process of adding in the property table.

Slight word of caution - if you have a very busy insert system and you may have several inserts in progress at the same time, you'll need extra steps to ensure that another insert (step 1) isn't done before step 2.  Unlikely you'll be THAT busy to start with!



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho