问题:
我正在尝试使用 wp cli 来做一些事情。作为示例更新 wordpress:
wp core update
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
path\to\wp-includes\wp-db.php:1564
Stack trace:
#0 path\to\wp-includes\wp-db.php(592): wpdb->db_connect()
#1 path\to\wp-includes\load.php(404):
wpdb->__construct(details)
#2 path\to\public\wp-settings.php(106): require_wp_db()
#3 phar://path/to/wp-cli.phar/php/WP_CLI/Runner.php(1182): require('C:\\path\\to\\...')
#4 phar://path/to/wp-cli.phar/php/WP_CLI/Runner.php(1107): WP_CLI\Runner->load_wordpress()
#5 phar://path/to/wp-cli.phar/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#6 phar://path/to/wp-cli.phar/php/bootstrap.php(75): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#7 phar://path/to/wp-cli.phar/php/wp-cli.php(23): WP_CLI\bootstrap()
#8 phar://C:/ in path/to\wp-includes\wp-db.php on line 1564
据我所知,错误出在 mysql_connect() 中。
我已阅读以下答案:
- Undefined function mysql_connect() - 这似乎建议下载一些软件包。我不愿这样做,因为我不明白他们在做什么(目前我正在使用 MAMP 运行 php,所以我不确定这是否会给我带来更多问题)但这确实向我暗示问题出在 php .ini 通知下面的尝试解决方案。
- Fatal error: Call to undefined function mysql_connect() - 我认为我的登录详细信息没有错误(网站本身可以正常工作)所以这似乎不是问题
尝试的解决方案 - php.ini
当我通过
检查正在使用哪个 php.ini wp cli 时wp--info
命令。它打印以下内容:
OS: Windows NT 10.0 build 17134 (Windows 10) i586
Shell: C:\Program Files\Git\usr\bin\bash.exe
PHP binary: C:\MAMP\bin\php\php7.2.1\php.exe
PHP version: 7.2.1
php.ini used:
WP-CLI root dir: phar://wp-cli.phar
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: C:\path\to\public
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.5.1
所以这里好像没有使用php.ini。所以我想我需要解决这个问题。为了做到这一点,我找到了 $WP_CLI_PHP_ARGS我正在尝试放入。现在我不是编码 super 巨星,但似乎我需要构建一个 bash 脚本来充当包装器,因为它们在 .phar 版本中不起作用,所以我合并了 two我在网上找到的包装器来创建这个:
#!/usr/bin/env sh
dir=$(d=${0%[/\\]*}; cd "$d"; pwd)
# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m $dir);
fi
fi
dir=$(echo $dir | sed 's/ /\ /g')
"${WP_CLI_PHP}" $WP_CLI_PHP_ARGS "${dir}/wp-cli.phar" "$@"
当我运行它时,它会发出各种提示。我想我犯了一些基本错误。 (我还在我的 .bash_profile 中添加了“export WP_CLI_PHP_ARGS=/C/MAMP/bin/php/php7.2.1/php.ini-production”)。
最佳答案
mysql_connect()
是 deprecated, as of PHP 5.5 , 并在 PHP 7 中删除。PHP 5.5 不是受支持的 PHP 版本,因此作者应更新其代码。
使用mysqli_connect()
相反。
关于php - 如何修复 wp cli 中的 mysql_connect() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50834815/