我有一个灯服务器上的数据库,并希望从我家使用Windows 7 PC连接到这个数据库并使用查询。使用php连接到灯服务器上的数据库
用腻子我可以用ssh连接服务器。首先连接到ssh,然后连接到mysql数据库。
在php中,我是否需要使用ssh2库(如phpseclib)和连接槽ssh2并使用交互式shell或者是否有直接与数据库连接的方式。因此跳过外壳?
谢谢。
我有一个灯服务器上的数据库,并希望从我家使用Windows 7 PC连接到这个数据库并使用查询。使用php连接到灯服务器上的数据库
用腻子我可以用ssh连接服务器。首先连接到ssh,然后连接到mysql数据库。
在php中,我是否需要使用ssh2库(如phpseclib)和连接槽ssh2并使用交互式shell或者是否有直接与数据库连接的方式。因此跳过外壳?
谢谢。
看看这个:
<?php
$connection = mysql_connect("localhost","root_user","root_password")
or die("problems connecting to DB.");
mysql_select_db("my_database",$connection)
or die("Problems selecting DB.");
$records = mysql_query("select id, name, school from students",$connection)
or die("Problems on querying " . mysql_error());
while ($record = mysql_fetch_array($records)) {
echo "id: " . $record['id'] . "<br>";
echo "name: " . $record['nombre'] . "<br>";
echo "school: " . $record['school'] . "<br>";
}
mysq_close($connection);
?>
SSH隧道是答案:http://statistics.berkeley.edu/classes/s133/mysqlt.html –
啊。现在试试这个! – Arvind
我得到了回应,但现在“访问拒绝用户'根'@'localhost'(使用密码:是)” – Arvind