mantisBT 常用的PHP代码
时间: 2023-07-09 07:47:25 浏览: 130
MantisBT 是一个开源的缺陷跟踪系统,使用 PHP 编写。以下是 MantisBT 常用的 PHP 代码示例:
1. 连接 MantisBT 数据库:
```php
$g_hostname = 'localhost';
$g_db_type = 'mysql';
$g_database_name = 'mantisbt';
$g_db_username = 'mantisbt_user';
$g_db_password = 'mantisbt_password';
$db = new PDO("$g_db_type:host=$g_hostname;dbname=$g_database_name;charset=utf8", $g_db_username, $g_db_password);
```
2. 获取 MantisBT 用户列表:
```php
$query = "SELECT id, username, realname FROM mantis_user_table";
$stmt = $db->query($query);
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
```
3. 创建 MantisBT 缺陷:
```php
$bug_data = array(
'project_id' => 1,
'reporter_id' => 2,
'handler_id' => 3,
'summary' => 'Test Bug',
'description' => 'This is a test bug',
'category_id' => 1,
'priority' => 3,
'severity' => 3,
'status' => STATUS_NEW
);
$bug_id = bug_create($bug_data);
```
4. 获取 MantisBT 缺陷列表:
```php
$query = "SELECT id, summary, status FROM mantis_bug_table";
$stmt = $db->query($query);
$bugs = $stmt->fetchAll(PDO::FETCH_ASSOC);
```
5. 更新 MantisBT 缺陷:
```php
$bug_id = 1;
$bug_data = array(
'summary' => 'Updated Summary',
'description' => 'Updated Description',
'priority' => 2,
'severity' => 2,
'status' => STATUS_RESOLVED,
'resolution' => RESOLVED_FIXED
);
bug_update($bug_id, $bug_data);
```
阅读全文