Connecting AppGini Database to Printer?

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Connecting AppGini Database to Printer?

Post by AEmpeno » 2021-04-01 14:47

We have this printer software, Bartender, and it supports MySQL and MariaDB. My AppGini project is saved to a local computer in the same network. I've been trying to connect my AppGini project to this software printer using this wizard. I tried several server paths - \\127.0.0.1\jfoodsqa or \\localhost\jfoodsqa but it's not connecting or something. The reason I'm trying to connect this is when I print a label I could pull out the data from the saved data in the Appgini database. Please see the attached screenshots.

I would like to know if anyone here has experience connecting their AppGini app to a 3rd party software maybe you can share and help me. Thank you in advance.
Attachments
Step 2 - MySQL Database.PNG
Step 2 - MySQL Database.PNG (99.47 KiB) Viewed 2691 times
Step 1 - Select Database Type.PNG
Step 1 - Select Database Type.PNG (143.64 KiB) Viewed 2691 times

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by jsetzer » 2021-04-01 15:05

I think this issue is more about connecting from a remote machine to a MySQL server rather than connecting to AppGini.

What comes in my mind:
- You will need a MySQL user/password who is allowed to connect and (at least) read from remote machines other than localhost
- both are on the same network, but can the print server reach the database server?
- the firewall may be denying remote access on port 3306. This may be the case on both computers (outgoing/incoming) but more likely on database server side
- depending on the printing software: I've seen problems with 64bit drivers and had to install and use 32bit mySQL drivers. But that was 5 - 10 years ago or something. So I'm not sure about status quo.

I'd start with ping, then telnet to port 3306, then create database user whatever@%, then grant access to database and tables.

Hope this helps!
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by jsetzer » 2021-04-01 15:29

Oh, I'm sorry. Maybe I have misunderstood your scenario.

Do you want to pull data from the remote database or do you want to send data from your webserver to the remote printer?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Re: Connecting AppGini Database to Printer?

Post by AEmpeno » 2021-04-01 18:08

What I would like to do is when I print a label the information would be coming from the AppGini database. For example, on my label, I have a "Lot Code" field and I would like to get that "Lot Code" from the production table in my AppGini database instead of manually typing the Lot Code.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by jsetzer » 2021-04-01 18:30

There are so many different ways depending on your specific infrastructure.

Maybe I have missed it, where is your printing software installed? Is it already connected to the printer? Is your printing software able to fetch data from mySQL? It it able to fetch and use JSON data?

Generally speaking, there are two possible data flow directions:
A) your printing software (installed on a remote print server, connected to the printer, pulling data from remote database server or via for example REST service. This depends in the software being installed there.
B) pushing data from the web server to a service installed on your printing server
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Re: Connecting AppGini Database to Printer?

Post by AEmpeno » 2021-04-01 19:12

Right now, I am doing a test mode, so the printing software is installed on my pc the same as my Appgini project database. I can print something if I'm doing it manually, input the information, or fetch data from an excel spreadsheet. I haven't tried the software to any MySQL or MariaDB format.

Once I'm comfortable with the connection setup/settings, I would like to eventually connect the Bartender software to my actual database run and saved it to a different PC/IP address.

I will def try your first suggestion, and we'll see from there. Thanks for the pointers!

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by onoehring » 2021-04-02 07:24

Hi,

I do not really understand the problem. Isn't it that you either can use the printer from PC A or you can not? As AG is a browser application, if you run it on PC A (in your browser) and you can print to that printer (if it's connected and the connection is working in general).
Jan's questions are good: IF your printing software pulls data from the AG database, it will need credentials to access that database and the printing should work. If it's the way around (that I described, and you are using AG from PC A and want to pint to that printer) it seems to be a general connection problem in Windows itself.
Well ... I might have got you wrong.

Olaf

AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Re: Connecting AppGini Database to Printer?

Post by AEmpeno » 2021-04-02 17:08

Sorry for the confusion. Thank you all for pointing me in the right direction, I think this is what I'm missing - "IF your printing software pulls data from the AG database, it will need credentials to access that database, and the printing should work." I have to figure out first, how to make database credentials and make them accessible to the printing software.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by onoehring » 2021-04-03 06:17

Hi,

you COULD use the same credentials as for your general AG application (if this is not a security risk). You can find those in the config.php file.
You could also create a new database user (if you have permissions to do so with phpmyadmin or adminer.

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by jsetzer » 2021-04-03 06:46

Scenario

Remote access (from a different computer) to your database server for pulling data:


Local user vs. remote user

In a usual webserver environment, by default there is only access for local users, for example for root@localhost. This is security related and very important!

In AppGini's config.php it usually only says "root". This (usually) means "root@localhost". This is different in MySQL from, for example named users in Microsoft SQL Server.

You will not be able to use for example root (which usually means root@localhost) + password if you try to connect from a different machine.

As mentioned before, if you need remote access, you will have to create a remote user* (or re-configure an existing user), for example ...

Code: Select all

myuser@%
... and then grant permissions on the database to that user.

* Note the "%"-character behind the "@". This means myuser can connect from any location and not only from localhost.

You can also work with an IP-address here, but caution: IP-Address may change (DNS/Dynamic IP) or may be cloaked.

More info on remote users in MySQL:
https://stackoverflow.com/questions/162 ... ote-access
https://www.digitalocean.com/community/ ... s-to-mysql
https://devdocs.magento.com/guides/v2.4 ... emote.html


Firewall

Usually MySQL is configured to use port 3306. This may be different depending on your installation. Firewalls usually deny access on that port by default. As mentioned before, if remote access still does not work with a remote user, check your firewall settings on both machines and allow port 3306.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

AEmpeno
Veteran Member
Posts: 72
Joined: 2018-01-04 18:48

Re: Connecting AppGini Database to Printer?

Post by AEmpeno » 2021-04-06 22:40

Thank you! I was able to connect to my local database.

Unfortunately, because I have several "lookup" fieldnames on my table so if I pick a record, it pulls/shows an "integer" number instead of the actual "name" of the product.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Connecting AppGini Database to Printer?

Post by jsetzer » 2021-04-07 02:20

Yes, AppGini stores the primary keys of related records due to referential integrity. Relational databases do so and should do so to avoid redundancies.

You have decided to pull data using a SQL reporting tool. This means you will have to write SQL or, if available in your reporting tool, use a Query Builder.

In your SQL command JOIN the related tables using SQLs INNER JOIN and/or LEFT JOIN commands.

[ Or (not recommended) add additional calculated fields for automatic calculation of values. But this is a waste of disk space and will not be up to date in certain scenarios ]

Tip: AppGini offers a beautiful function get_sql_from("TABLENAME") with parameters. This function already returns the FROM-part including all joined tables. It also cares for permissions. There are more functions for getting the field-values instead of primary keys. This means you can, for example, create a custom page (for Admin only) and just let AppGini display the SQL for a table. Then copy that SQL command into your database tool or reporting tool.

Beware: whenever you change your model, for example add more lookup fields, you may have to change your SQL command in your reports.

This actually means: in your remote database tool(s) you have to implement a SQL statement and keep it up to date, which may become a lot of work and may lead to errors or unexpected results in output, especially on changes. That's the reason for different approaches like for creating REST services on serverside or for sending data instead of pulling data. Those alternatives have been mentioned before. Keeping the structure and logic at a central place (webserver) is always a good idea ("single-source") and allows all remote clients to just consume data and don't care about the internal model instead of re-implementing a copy of the model in SQL per (remote) consumer. Additionally, consumers don't have to configure and grant permissions to a remote user, when using the REST service- or send-data-approach.

Anyway, when consuming data by fetching it directly from the database server (this is your scenario) there is no other way than writing SQL and joining related tables on the foreign key fields.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply