Dysan Posted March 16, 2008 Share Posted March 16, 2008 Hi, Using PHP & MySQL, how does one create a relational database? Link to comment https://forums.phpfreaks.com/topic/96397-mysql-relational-database/ Share on other sites More sharing options...
Dysan Posted March 16, 2008 Author Share Posted March 16, 2008 How do I convert the following database into a relational database? The database contains peoples favorite food and drinks. if (mysql_query("CREATE DATABASE db",$con)) { echo "Database Created!"; } else { echo mysql_error(); } mysql_select_db("db", $con); $sql = "CREATE TABLE persons ( name text, )"; mysql_query($sql,$con); $sql = "CREATE TABLE items ( favouritedrink text, favouritefood text, )"; mysql_query($sql,$con); mysql_close($con); Link to comment https://forums.phpfreaks.com/topic/96397-mysql-relational-database/#findComment-493385 Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 ad an id field on your person table, id int unsigned autoincrement primary key. then add a field on the items table called person_id int unsigned. relate the tables together by including the id of a record in the person table as the person_id for a record in the items table. Link to comment https://forums.phpfreaks.com/topic/96397-mysql-relational-database/#findComment-493394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.