如何将卡片模板连接到 MySQL 或 MariaDB
您将学到什么
使用 Database Wizard 将卡片模板连接到 MySQL 或 MariaDB 服务器上的表,将各列关联到卡片对象,并在 Operating mode 中显示记录。两种服务器的连接方式基本相同,存在少数差异的地方会特别注明。记录保留在服务器上:eMedia Cards 会对其进行实时读写。
MySQL 与 MariaDB 简介
-
向导中统一提供 MySQL / MariaDB 这一项,支持 MySQL 8 和当前版本的 MariaDB。在 Windows 上,请在 Server: 下选择与您服务器匹配的 MySQL 或 MariaDB。在 Mac 上没有此选项:内置客户端同时支持两者。
-
Windows:每种服务器类型使用各自免费的 64 位 Unicode ODBC 驱动程序,每台 PC 只需安装一次:MySQL 使用 MySQL ODBC Unicode driver,MariaDB 使用 MariaDB ODBC 3.2 driver。您无需创建 ODBC 数据源(DSN)。
-
Mac:eMedia Cards 内置了 MySQL 和 MariaDB 客户端,无需安装驱动程序。
-
登录凭据:用户名和密码。向导中没有用于二次登录验证的字段。
-
MySQL 8 的默认登录方式在启用或未启用 SSL 时均可使用。在 Windows 上,ed25519、PARSEC 和 GSSAPI 等 MariaDB 登录方式需要将 Server: 设为 MariaDB 并使用 MariaDB 驱动程序。
-
SSL: 提供 Off、Prefer、Require、Verify certificate 和 Verify certificate and server name。Require 会加密连接,但不校验证书。两个 Verify 选项会校验证书,并支持通过可选的 CA certificate file (optional): 指定自签名或私有证书。使用 MariaDB 时,Verify certificate 还会检查服务器名称。
-
Port: 默认为
3306。1 到 65535 之间的任何端口均可使用。 -
连接超时限制:在 Mac 上为 15 秒。在 Windows 上,eMedia Cards 本身不设置限制,适用驱动程序自身的超时设置。
-
密码会随模板的连接详情一同保存。
-
要添加、修改或删除记录,表中必须有一个值互不相同的键列(通常是主键),且您的登录账号需要具备该表的写入权限。
-
ODBC / DSN 这一项(Any ODBC data source (DSN))是另一种连接类型,仅限 Windows,且需要 Professional 版。连接 MySQL 或 MariaDB 无需使用它。
-
适用于 Windows 和 Mac。
开始之前
-
Standard 版或更高版本。在 Windows 的 Starter 版中,点击 Next 会弹出升级提示,向导不会继续。在 Mac 上,系统会在连接时检查版本。
-
您自己的 MySQL 8 或当前版本 MariaDB 服务器,以及对该表拥有读取权限(如需添加、修改或删除记录还需写入权限)的登录账号。
-
在 Windows 上,需安装对应服务器类型的免费 64 位驱动程序。如果缺失,向导会显示 Database driver not installed,并提供 Download MySQL ODBC 或 Download MariaDB ODBC 按钮。
-
本例使用
Larkspur Hill School Student Card.eccs,这是一张仅正面的 CR80 学生证,尚未连接数据库。其文本对象 LastName、FirstName、Class 和 StudentID 以及图片对象 Photo 的名称与表中的列名一致。条形码对象会将 StudentID 打印为 Code 128 条形码。 -
数据脚本为
larkspur_school.sql:它会在服务器上创建larkspur_school数据库及其中唯一的表students(共 20 行),包含列Id(主键,由服务器自动编号)、StudentID、FirstName、LastName、Class和Photo。请使用您常用的 MySQL 或 MariaDB 工具在服务器上运行该脚本。 -
模板、SQL 脚本、学生照片和
README.txt均在上方下载中提供。请将Photos文件夹放在模板旁边。学校、学生和人脸照片均为虚构。
在截图中,服务器名称和用户名为示例值:Server: school-server,User ID: cards_app。请使用您自己的服务器、用户名和密码。
如何将 MySQL 或 MariaDB 表连接到模板
-
解压示例文件,在您的服务器上运行
larkspur_school.sql,然后打开Larkspur Hill School Student Card.eccs。模板会在 Operating mode 中打开。 -
切换到 Design mode。
-
点击 Tools > Connect to database...。如果弹出 Database Connected 消息,请点击 Disconnect & Continue。Database Wizard 会在第 1 步 Connection 打开。

-
在 Select a database connection type: 下,点击 MySQL / MariaDB。在 Windows 的 Standard 版中,ODBC / DSN 为灰色不可用。
-
点击 Next。第 2 步 Configure Columns 会在 Connect to MySQL or MariaDB: 界面打开。在 Windows 上,MySQL driver found 消息会显示驱动程序版本。

-
仅限 Windows:在 Server: 旁保留 MySQL,如果使用 MariaDB 服务器则选择 MariaDB。驱动程序提示消息会切换为对应服务器类型的驱动程序。在 Mac 上没有服务器类型选择:直接进入下一步。
-
在 Server: 框中输入服务器名称或 IP 地址。此处为
school-server。 -
在 Port: 中保持
3306,除非您的服务器使用其他端口。 -
在 Database: 中输入数据库名称。此处为
larkspur_school。 -
在 User ID: 中输入您的用户名。此处为
cards_app。 -
在 Password: 中输入您的密码。密码会显示为圆点。
-
在 SSL: 中保持 Prefer。如果服务器仅接受加密连接,请选择 Require;如需校验证书,请选择 Verify 相关选项;如果服务器未启用 SSL,请选择 Off。
-
点击 Test connection。消息会显示数据库、服务器以及找到的表数量:此处为 Connected to larkspur_school on school-server. 1 table found. 只有在测试成功后才能点击 Next。

-
在 Source: 中,根据您的数据库组织方式选择 eMedia Cards 读取记录的方式:
-
Table:单个表中的记录。在 Table: 中选择。
-
View:视图中的记录。在 View: 中选择。
-
SQL:一条 SQL 语句的执行结果。在 SQL statement: 中输入。
此处选择:Table。
-
-
在 Table: 中选择您的表。此处为 students。
-
在 Key column: 中检查表的主键。在本例中为 Id。
-
查看 Preview (first rows) 表格。此处显示:Showing the first 10 rows.
-
点击 Next。第 3 步 Operator Fields 打开。

-
在 Display 和 Edit 列中,取消勾选操作员不应查看或修改的字段。Id 显示为 Filled in by the database:由于服务器会为新记录自动编号,其 Edit 复选框处于关闭状态。可选:在 Operator permissions 下,取消勾选 Add records、Modify records 或 Delete records。
-
Sort 用于设置 Operating mode 中记录的排列顺序。向导会默认建议按某一字段排序,此处为 Id。如需更改,请在另一个字段上点击 Sort:工具提示会显示 Sort A to Z 或 Sort Z to A。排序为可选项:您也可以稍后在 Operating mode 中点击记录网格的列标题进行排序。每次点击会依次切换为 Sort A to Z、Sort Z to A,然后取消排序(恢复模板的默认排序)。点击列标题设置的排序不会随模板保存。
-
点击 Next。第 4 步 Link & Summary 打开。

-
检查 Connection:、Total columns: 和 Linked objects:。此处分别为 MySQL / MariaDB、6 和 5。名称与卡片对象相同的每一列都会自动关联。Photo 的类型为 Image Path。Id 保持为 (none):它不会显示在卡片上。
-
点击 Connect Data Source。

-
点击 View > Operating mode。卡片和记录网格会显示 MySQL 或 MariaDB 表中的行数据。

提示
-
MySQL 或 MariaDB 表就是实时数据库。在 Operating mode 中所做的更改会写入服务器。点击 Requery 可读取其他用户所做的更改。
-
名称与卡片对象相同的列会自动关联。
-
图片列存储文件名,例如
LHS-26001.jpg。eMedia Cards 会在模板的图片文件夹(此处为模板旁的Photos文件夹)中查找这些文件。 -
当您添加记录时,服务器会自动为 Id 分配下一个编号。
-
Could not connect: 后面的文本来自服务器或驱动程序,可能会使用服务器的语言显示。
常见错误
| 现象 | 原因 | 解决方法 |
|---|---|---|
| Database driver not installed: MySQL 8 and newer needs the free MySQL ODBC Unicode driver (64-bit). Install it, then click Check again. | Windows:此 PC 上未安装 MySQL 驱动程序。 | 点击 Download MySQL ODBC,安装 64 位 Unicode 驱动程序,然后点击 Check again。 |
| Database driver not installed: MariaDB needs the free MariaDB ODBC 3.2 driver (64-bit). Install it, then click Check again. | Windows:此 PC 上未安装 MariaDB 驱动程序。 | 点击 Download MariaDB ODBC,安装 64 位驱动程序,然后点击 Check again。 |
| Only the ANSI driver is installed. eMedia Cards needs the Unicode 64-bit driver. Install it, then click Check again. | 仅安装了 ANSI 驱动程序。 | 从同一安装包中安装 Unicode 驱动程序,然后点击 Check again。 |
| Only the 32-bit driver is installed. eMedia Cards is a 64-bit app and needs the 64-bit driver. Install it, then click Check again. | 仅安装了 32 位驱动程序。 | 安装 64 位驱动程序,然后点击 Check again。 |
| Could not connect: The user name or password is incorrect. Check them and try again. | User ID: 或 Password: 错误。 | 重新输入用户名和您的密码。 |
| This server uses a MariaDB login method. Select MariaDB and install that driver. | Windows:服务器为 MariaDB,且您的登录账号使用了 MariaDB 登录方式。 | 在 Server: 旁选择 MariaDB,并安装 MariaDB 驱动程序。 |
| This server uses a MySQL login method. Select MySQL and install that driver. | Windows:服务器为 MySQL,但选择了 MariaDB。 | 在 Server: 旁选择 MySQL,并安装 MySQL 驱动程序。 |
| This server requires a secure (SSL) connection. Turn on SSL. | SSL: 设为了 Off,但服务器仅接受加密连接。 | 请选择 Prefer 或 Require。 |
| Could not connect:,后接有关证书的消息 | 选择了 Verify 选项,但服务器的证书不受信任、已过期或与服务器名称不匹配。 | 对于自签名或私有证书,请在 CA certificate file (optional): 中选择其文件。或者向管理员申请有效证书。 |
| Connected to larkspur_school on school-server. 1 table found. This server is MySQL. The MySQL driver is the one meant for it. | Windows:测试连接成功,但 Server: 与服务器类型不匹配。这是一条警告,而非错误。 | 请选择消息中指明的服务器类型。 |
| The MySQL / MariaDB login "cards_app" can read "students" but isn't allowed to change it. Ask your database administrator for write access. | 您的登录账号仅有读取权限。 | 请向数据库管理员申请该表的写入权限。 |
| The MySQL / MariaDB login "cards_app" isn't allowed to read "students". Ask your database administrator for read access. | 您的登录账号对该表没有任何权限。 | 请向数据库管理员申请该表的读取权限。 |