【问题标题】:Create a new column or field with PHP PDO使用 PHP PDO 创建新列或字段
【发布时间】:2016-12-15 12:01:46
【问题描述】:

如何使用 PHP PDO 在现有 Access 数据库 (resultdb) 中创建新列或字段 (idnew)?。

【问题讨论】:

  • 运行 ALTER..ADD 查询,ALTER TABLE resultdb ADD idnew int - 尽管使用 phpMyAdmin 之类的工具使这变得容易得多。
  • 您不会使用数据库管理工具而不是代码来创建列(或以任何方式更改架构)吗?

标签: php pdo


【解决方案1】:

您可以使用查询功能以及准备好的语句功能创建新列。你应该使用哪一个取决于你想用它做什么。

示例 1

$pdo->query('ALTER TABLE resultdb ADD idnew INT(11)');

示例 2

function addColumn($column, $type)
{
  $query = $pdo->prepare('ALTER TABLE resultdb ADD :column :type');
  $query->execute(array(':column' => $column, ':type' => $type));
}
addColumn('idnew', 'INT(11)');

请注意,这样做不会破坏网站中内置的任何功能。

【讨论】:

  • 不,您不能将数据解析为execute() for ALTER
猜你喜欢
  • 2012-07-15
  • 1970-01-01
  • 2011-09-20
  • 2010-12-26
  • 2018-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
相关资源
最近更新 更多