在PHP中设置默认MySQL套接字,pdo_mysql.default_socket PHP 5.3

前端之家收集整理的这篇文章主要介绍了在PHP中设置默认MySQL套接字,pdo_mysql.default_socket PHP 5.3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在设置 MySQL的默认PDO套接字位置时遇到问题,而没有通过将PDO类初始化为变量来实现.我试过改变MysqL.default_socket变量.但没有喜悦.目前唯一有效的方法是通过类DSN实例化.

PHP.ini内容

[PHP]
engine = On
zend.ze1_compatibility_mode = Off
short_open_tag = On
asp_tags = Off
precision    =  14
y2k_compliance = On
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func=
serialize_precision = 100
allow_call_time_pass_reference = Off
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions =
disable_classes =
expose_PHP = Off
max_execution_time = 300
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_NOTICE
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
variables_order = "EGPCS"
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
extension_dir = "/usr/lib64/PHP/modules"
enable_dl = On
file_uploads = On
upload_max_filesize = 500M
allow_url_fopen = On
default_socket_timeout = 60

[Syslog]
define_syslog_variables  = Off

sendmail_path = /usr/sbin/sendmail -t -i

[sql]
sql.safe_mode = Off

[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1

[MysqL]
MysqL.allow_persistent = On
MysqL.max_persistent = -1
MysqL.max_links = -1
MysqL.default_port = 3306
MysqL.default_socket = /home/MysqL/MysqL.sock
MysqL.default_host = 127.0.0.1
MysqL.default_user = conner
MysqL.default_password = danica4eva
MysqL.connect_timeout = 60
MysqL.trace_mode = Off

[MysqLi]
MysqLi.max_links = -1
MysqLi.default_port = 3306
MysqLi.default_socket = /home/MysqL/MysqL.sock
MysqLi.default_host = 127.0.0.1
MysqLi.default_user = conner
MysqLi.default_pw = danica4eva
MysqLi.reconnect = Off

[msql]
msql.allow_persistent = On
msql.max_persistent = -1
msql.max_links = -1

[Postgressql]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0

[Sybase]
sybase.allow_persistent = On
sybase.max_persistent = -1
sybase.max_links = -1
sybase.min_error_severity = 10
sybase.min_message_severity = 10
sybase.compatability_mode = Off

[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10

[bcmath]
bcmath.scale = 0

[Informix]
ifx.default_host =
ifx.default_user =
ifx.default_password =
ifx.allow_persistent = On
ifx.max_persistent = -1
ifx.max_links = -1
ifx.textasvarchar = 0
ifx.byteasvarchar = 0
ifx.charasvarchar = 0
ifx.blobinfile = 0.
ifx.nullformat = 0

[Session]
session.save_handler = files
session.save_path = "/var/lib/PHP/session"
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = PHP
session.gc_probability = 1
session.gc_divisor     = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 1
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

[MSsql]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = Off
mssql.secure_connection = Off

[Verisign Payflow Pro]
pfpro.defaulthost = "test-payflow.verisign.com"
pfpro.defaultport = 443
pfpro.defaulttimeout = 30

[Tidy]
tidy.clean_output = Off

[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400

zend_extension = /etc/ioncube/ioncube_loader_lin_5.3.so

如您所见,我已经更改了PHP.ini文件中的默认套接字设置,但是当我尝试连接到MysqL时,我仍然在PDO中收到套接错误.它让我相信PDO驱动程序没有使用PHP.ini中的设置.我确信有一些配置PDO的方法,但我的PHP.ini中没有任何内容.是否应该在PHP.ini中设置PDO,或者它们是否包含在其他地方?

PDO MysqL驱动程序有不同的ini设置.它被称为
pdo_MysqL.default_socket

你试过设置这个ini值吗?请参考http://php.net/manual/de/ref.pdo-mysql.php

使用以下配置选项在编译期间也可以影响该值:

--with-MysqL-sock=/my/path/MysqL.sock

更新:我发现问题是已知的PHP bug.

第一:当使用127.0.0.1作为db主机而不是localhost时,可以解决该问题. PHP将以这种方式通过TCP套接字连接.

要更改位置,您必须从具有特殊配置选项的源编译PHP.我成功地使用以下(基本)命令行更改了MysqL套接字的位置:

./configure \
  --with-MysqL \
  --with-MysqLi=MysqLnd \
  --enable-pdo \
  --with-pdo-MysqL=MysqLnd \
  --with-MysqL-sock=/home/MysqL/MysqLd.sock

 make
 make install

最后的伎俩结合了最后两个. –with-MysqL-sock = file设置.sock文件的位置,但只有在–with-pdo-MysqL =设置为MysqLnd(MysqL本机驱动程序)时才使用它.如果缺少此选项,pdo将与系统中的libMysqLclient链接.因此,您还可以重新编译libMysqLclient(使用已修改套接字路径)并保持PHP不变.

注意:这只是使PHP使用PDO的基本配置.如果您需要其他扩展(如json,xml等),则需要其他配置选项.如果以这种方式执行(原始发行版)版本,您将找到Linux发行版用于编译PHP的配置:PHP -i.

猜你在找的PHP相关文章