I have a database on a lamp server and want to connect to this database with a windows 7 pc from my home and use queries.
With putty I can connect with the server with ssh. First connect with ssh, then connect to the mysql database.
In php do I need to use ssh2 libraries like phpseclib and connect trough ssh2 and use the interactive shell or is there a way to connect with the database directly. Thus skipping the shell?
Thanks.
Take a look at this:
<?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);
?>