-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenable-sqlite.ps1
More file actions
67 lines (55 loc) · 2.1 KB
/
enable-sqlite.ps1
File metadata and controls
67 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# PHP SQLite 扩展启用脚本
Write-Host "========================================" -ForegroundColor Green
Write-Host "启用 PHP SQLite 扩展..." -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
$phpIniPath = "F:\Program Files\php-8.4.6-Win32-vs17-x64\php.ini"
if (-not (Test-Path $phpIniPath)) {
Write-Host "❌ php.ini 文件不存在: $phpIniPath" -ForegroundColor Red
exit 1
}
Write-Host "✅ 找到 php.ini 文件: $phpIniPath" -ForegroundColor Green
# 读取 php.ini 内容
$content = Get-Content $phpIniPath -Raw
# 启用 SQLite 扩展
$extensions = @(
"sqlite3",
"pdo_sqlite",
"openssl",
"curl",
"fileinfo",
"mbstring"
)
$modified = $false
foreach ($ext in $extensions) {
$pattern = ";extension=php_$ext.dll"
$replacement = "extension=php_$ext.dll"
if ($content -match [regex]::Escape($pattern)) {
$content = $content -replace [regex]::Escape($pattern), $replacement
Write-Host "✅ 已启用扩展: $ext" -ForegroundColor Green
$modified = $true
} else {
Write-Host "⚠️ 扩展 $ext 可能已启用或不存在" -ForegroundColor Yellow
}
}
if ($modified) {
# 写回 php.ini
Set-Content -Path $phpIniPath -Value $content -Encoding UTF8
Write-Host "✅ php.ini 文件已更新" -ForegroundColor Green
} else {
Write-Host "⚠️ 没有需要修改的扩展" -ForegroundColor Yellow
}
Write-Host "========================================" -ForegroundColor Green
Write-Host "验证扩展状态..." -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
# 验证扩展
$phpModules = php -m
foreach ($ext in $extensions) {
if ($phpModules -contains $ext) {
Write-Host "✅ $ext 已启用" -ForegroundColor Green
} else {
Write-Host "❌ $ext 未启用" -ForegroundColor Red
}
}
Write-Host "========================================" -ForegroundColor Green
Write-Host "SQLite 扩展配置完成!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green