使用PDO创建新的SQLite DB [英] Creating new SQLite DBs with PDO

查看:109
本文介绍了使用PDO创建新的SQLite DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的下一个项目中提供一个设置功能,我想知道是否可以从PDO创建一个SQLite 3数据库,或者我只是坚持通过DSN连接到现有的数据库?

I want to provide a setup feature in my next project and I'm wondering if it's possible to create a SQLite 3 database from scratch with PDO or I'm just stuck at connecting to existing databases via DSN?

如果PDO不可能通过PHP创建一个新的数据库?

If it isn't possible with PDO is there any way to create a new DB via PHP?

推荐答案

当您打开一个不存在的连接时,将创建一个新的sqlite数据库。你可以检查文件是否存在,如果没有,那么只需创建一个新的数据库连接并插入表。

A new sqlite database is created when you open a connection to one that doesn't exist. You can just check if the file exists, and then if it doesn't, then just create a new database connection and insert the tables.

这篇关于使用PDO创建新的SQLite DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆