我正在尝试通过laravel连接到PostgreSQL数据库,以便让php工匠迁移,但是我收到了错误
[PDOException]找不到驱动程序
查看类似的问题,在php.ini
中启用扩展程序,但未解决我的问题,仍然给我同样的错误。
在我的代码的其他部分,我使用数据库,我可以添加记录,所以我认为我的设置数据库正确。我不明白这个错误。
Database.php文件:
<?php return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8', 'prefix' => '',
'schema' => 'public',
],
],
'migrations' => 'migrations',
]; ?>
答案 0 :(得分:0)
检查您是否有import subprocess
import sys
import shutil
import os
class NetworkConfiguration:
def __init__(self):
self.ntype=""
self.hostname=""
self.domain=""
self.pdns=""
self.sdns=""
self.ip=""
self.netmask=""
self.gway=""
self.files=["/etc/sysconfig/network/ifcfg-eth0",
"/etc/sysconfig/network/routes",
"/etc/resolv.conf",
"/etc/HOSTNAME"
]
def writeIntoFile(self,filename,s,mode):
f=open(filename,mode)
f.write(s)
f.close()
def buildString(self,filename):
ret_str=""
if filename == self.files[0] :
ret_str="DEVICE=eth0"
ret_str+="\n"+"STARTMODE=auto"
ret_str+="\n"+"BOOTPROTO="
if self.ntype=="s":
ret_str+="static"
else:
ret_str+="dhcp"
ret_str+="\n"+"USERCONTROL=no"
ret_str+="\n"+"ONBOOT=yes"
if self.ntype=="s":
ret_str+="\n"+"IPADDR="+self.ip
ret_str+="\n"+"NETMASK="+self.netmask
elif filename==self.files[1]:
if self.ntype=="s":
ret_str="defualt "+self.gway+" - -"
elif filename==self.files[2]:
ret_str="search "+self.domain
ret_str+="\n"+"nameserver "+self.pdns
if self.sdns!="":
ret_str+="\n"+"nameserver "+self.sdns
elif filename==self.files[3]:
ret_str=self.hostname+"."+self.domain
return ret_str
def runProcess(self,args):
p=subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
return p.communicate()
#------------------------Class Ends Here---------------------------------------
nCog=NetworkConfiguration()
# Recieving arguments from commmand line.
#sequence is: network_type,hostname,domain,primary_dns,ip,netmask,gateway,secondry_dns
# note : IP, Netmask, gateway are not required in case of DHCP.
try:
nCog.ntype=sys.argv[1]
if nCog.ntype=="s" and len(sys.argv)<8:
raise Exception("Too few arguments passed for static configuration!!!")
elif nCog.ntype=="d" and len(sys.argv)<5:
raise Exception("Too few arguments passed for DHCP configuration!!!")
elif nCog.ntype!="s" and nCog.ntype!="d":
raise Exception("Not a valid network type!!!")
nCog.hostname=sys.argv[2]
nCog.domain=sys.argv[3]
nCog.pdns=sys.argv[4]
if nCog.ntype=="s":
nCog.ip=sys.argv[5]
nCog.netmask=sys.argv[6]
nCog.gway=sys.argv[7]
if len(sys.argv)==9:
nCog.sdns=sys.argv[8]
elif len(sys.argv)==6:
nCog.sdns=sys.argv[5]
except Exception, e:
print(e)
# Writing network configurations into the appropriate files.
for f in nCog.files:
ret_str=nCog.buildString(f)
nCog.writeIntoFile(f,ret_str,"w")
# Setting the hostname
o, e=nCog.runProcess(['hostname',nCog.hostname])
# restart the network
o, e=nCog.runProcess(['service','network restart'])
print("restarting the network:\n------------------------------------")
print("output: "+o+"\n error: "+e)
# Adding gateway ip to the routing table in case static ip is assigned.
print os.system("sudo ip route add default via %s" % (nCog.gway))
延期。
你可以
pdo_pgsql
看到它。