通过ssh连接mysql的php代码怎么写

通过ssh连接mysql的php代码怎么写,第1张

通过ssh连接mysql的php代码

shell_exec("ssh -f -L 127.0.0.1:3307:127.0.0.1:3306 [email protected] sleep 60 >>logfile")$db = mysqli_connect("127.0.0.1", "sqluser", "sqlpassword", "rjmadmin", 3307)

DB接口:

package org.xxx.dbc

import java.sql.Connection

public interface IDatabaseConnection {

public Connection getConnection() throws Exception

public void close() throws Exception

}

------------------------------------------------------------------

实现:

package org.xxx.dbc.impl

import java.sql.Connection

import java.sql.DriverManager

import org.xxx.dbc.IDatabaseConnection

public class OracleDatabaseConnection implements IDatabaseConnection {

public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"

public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:db1" public static final String DBUSER = "name"

public static final String DBPASS = "pass"

private Connection conn = null

@Override

public void close() throws Exception {

// TODO Auto-generated method stub

try {

if (this.conn != null) {

this.conn.close()

}

} catch (Exception e) {

throw e

}

}

@Override

public Connection getConnection() throws Exception {

// TODO Auto-generated method stub

try {

Class.forName(DBDRIVER)

this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS)

} catch (Exception e) {

throw e

}

return this.conn

}

}

----------------------------------------------------------------------------------

工厂

package org.xxx.dbc.factory

import org.xxx.dbc.IDatabaseConnection

import org.xxx.dbc.impl.OracleDatabaseConnection

public class DBCFactory {

public static IDatabaseConnection getOracleDatabaseConnection()throws Exception {

return new OracleDatabaseConnection()

}

}

看错了,以为是oracle .不影响使用


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6171564.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-17
下一篇 2023-03-17

发表评论

登录后才能评论

评论列表(0条)

保存