简体   繁体   English

从远程WAMP服务器上的终端运行本地php脚本

[英]Run local php scripts from Terminal on remote WAMP server

I'm trying to connect to a remote WAMP server using a simple php script. 我正在尝试使用简单的php脚本连接到远程WAMP服务器。 I'm able to successfully execute scripts like this one: 我能够成功执行如下脚本:

<?php
    $counter = 0;
    while($counter < 20) {
        $counter++;
        echo $counter;
        echo "\n";
    }

    echo "Done! Counter: ";
    echo $counter;
    echo "\n";
?>

But, unable to execute basic scripts on my laptop that try to connect to my remote server, such as below. 但是,无法在笔记本电脑上执行尝试连接到远程服务器的基本脚本,如下所示。 The following line just freezes and the php script never stops running. 以下行只是冻结,并且php脚本永远不会停止运行。 I am executing it by cd 'ing into the directory with the file and running php test.php . 我正在通过cd进入带有文件的目录并运行php test.php来执行它。

$link = mysqli_connect($db_host, $db_user, $db_pass, $db_database, $db_port) or die(mysqli_error($link)); 

This prints bool(true) : 这打印bool(true)

var_dump(function_exists('mysqli_connect'));

Do I need to install anything to get this to work? 我需要安装任何东西才能使其正常工作吗? I've done all the usual fixes, changed the .conf files on my local server and have an Android app that connects successfully, but now I just want to do operations on a MySQL table from Terminal but am unable to. 我已经完成了所有通常的修复,更改了本地服务器上的.conf文件,并具有成功连接的Android应用程序,但是现在我只想在Terminal的MySQL表上执行操作,但无法执行。

The correct call to see any errors generated by a mysqli_connect() is mysqli_connect_error() and not mysqli_error($link)); 查看mysqli_connect()生成的任何错误的正确调用是mysqli_connect_error()而不是mysqli_error($link));

So change the connection call to 因此将连接呼叫更改为

$link = mysqli_connect($db_host, $db_user, 
                       $db_pass, $db_database, 
                       $db_port) 
          or die(mysqli_connect_error()); 

Or as suggested in the manual 或按照手册中的建议

$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

You will also need to be using a Userid/password that is configured to allow access from a remote connection. 您还需要使用配置为允许从远程连接访问的Userid /密码。 The default root will not allow remote connections, and should not be amended to allow remote connections. 默认root将不允许远程连接,并且不应修改为允许远程连接。

You may find this page in the manual useful to create a new user account in MYSQL 您可能会发现手册中的页面对于在MYSQL中创建新用户帐户很有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM