0

So I am trying to create a blog in php and mysql. I am not sure how this is going to work out there. Just let me know if i am on the right track with the DB.

Let's say i have database called blog with table user and posts. This is for multiuser blog. So I want to connect userid with the posts table. So I need to make userid field common in both tables right?

e.g.

create table users (
id int auto_increment primary key,
userid int NOT NULL, 
password varchar(40) NOT null, 
)

create table posts(
id int auto increment primary key, 
userid not null, 
post_header varchar(400) NOT NULL, 
post_body text NOT NULL)
foreign key userid reference users(userid);

Is this a right approach ? Also I am thinking about making procedural way of accessing data with mysqli. Is there anything wrong with procedural approach?

2
Contributors
1
Reply
17
Views
4 Years
Discussion Span
Last Post by pritaeas
0

Is this a right approach ?

Yes. But userid in the users table is not necessary. posts.userid should point to users.id. You can make it a foreign key if you like.

Also I am thinking about making procedural way of accessing data with mysqli. Is there anything wrong with procedural approach?

No, nothing wrong with it. MySQLi is the right choice, although you can consider PDO (but that is not procedural).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.