gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:36:44 28 4
gpt4 key购买 nike

我在为 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/en/ref.pdo-mysql.php

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

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

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

首先:您可以解决使用 127.0.0.1 作为数据库主机而不是本地主机时的问题。 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 native 驱动程序)。如果缺少此选项,pdo 将链接到系统中的 libmysqlclient。因此,您还可以重新编译 libmysqlclient(使用修改后的套接字路径)并保持 php 不变。

注意:这只是使 PHP 与 PDO 一起工作的基本配置。如果您需要额外的扩展(如 json、xml 等),您将需要额外的配置选项。如果您以这种方式执行(原始发行版)版本,您将找到您的 Linux 发行版用于编译 PHP 的配置:php -i

关于mysql - 在 PHP 中设置默认 MySQL 套接字,pdo_mysql.default_socket PHP 5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14205826/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com