Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

How to connect a database to a table in Grav

Started by Ton Haarmans 5 years ago · 24 replies · 3438 views
5 years ago

For a client I need to know the following:
There are tables on certain pages that need to be automatically filled and updated with data from a MySQL database. I have installed the Database and Views plugin. I have no clue how to connect the tables with the database. I am a front end designer... Could somebody help me? If this is not possible the client's choice for a CMS will be Drupal 8 😦 .

5 years ago

Didn't have to deal with DBs on Grav, but I'm afraid you still might have to do some coding. To get your connection. Also might find this article useful.

5 years ago

Thanks Karmalakas. I am not afraid of the coding, but i need to know what code and where to put it...

The article looks very promising!!! Thanks

5 years ago

@TonHaarmans:
i need to know what code and where to put it

What I understand from the docs, you'd need to create a plugin, that would connect to your DB by using $this->grav['database'], which is initiated by Database plugin. Also in your plugin you probably could do most of the logic that is described in that article I posted

5 years ago

Making a plugin! I will try. Never done that before...

5 years ago

I might try to write a plugin actually later. Sounds interesting and might be challenging :)

5 years ago

@TonHaarmans,
as @Karmalakas already stated, you will need to create a plugin that can connect to a mysql database - be aware that the database plugin that was mentioned only can connect to a sqlite DB.
for mysql, you will probably need symfony/doctrine.

5 years ago

@Karmalakas ,
that would be a cool plugin, much appreciated by many users, IMHO 😃

5 years ago

So the point would be for me: how to make the connection between the DB and a page or part of a page (like a table width different data in different table cells).

5 years ago

@Karmalakas ,
I think, just PDO itself is not enough, as this is just a wrapper, at least PDO_MYSQL driver will be necessary in this case.
this is also the reason why I proposed to use symfony/doctrine, which would probably be easier to integrate in Grav (not sure, never done that).

5 years ago

In fact, to fill and update from an Excel sheet would be enough....

5 years ago

@TonHaarmans:
to fill and update from an Excel sheet would be enough

Databases are so much easier :) And I mean SO SO MUCH easier :D Parsing Excel sheets is a pain.. Been there, done that :D

5 years ago

hm, if your data is in an excel sheet, why not just save that as csv and import that in grav via table importer plugin ?

5 years ago

yes, parsing excel sheets directly is a PITA 😃

5 years ago

no, importing csv should be easy.

5 years ago

CSV is a different story :) These are fine
As @hoernerfranz mentioned, you could try that plugin in CSV case

5 years ago

Yes, will try that!
The main Database of my client is written in Access. This can spit out a csv, which can be uploaded and then imported into Grav. If that can work, that would be awesome.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago