Note that there are some explanatory texts on larger screens.

plurals
  1. POConnecting from VM to MySQL
    primarykey
    data
    text
    <p>I'm having trouble connecting to a MySQL database on my host OS (Win 7) from my Oracle VirtualBox running Ubuntu. I wrote this php code in order to connect but I keep receiving an error connecting:</p> <pre><code>&lt;?php $dsn = 'mysql:host=192.168.1.9;dbname=finance'; $db_username = 'sdb_user'; $db_password = 'password'; try { $db = new PDO($dsn, $db_username, $db_password); }catch (PDOException $e) { $error_message = $e-&gt;getMessage(); include('../errors/database_error.php'); exit(); } $query = 'SELECT * FROM books'; $books = $db-&gt;query($query); foreach ($books as $book) { echo $book['title']; } ?&gt; </code></pre> <p>I know the code works, because I can get it to run from my Windows 7 host OS using localhost instead of the IP address, and I know that both Linux on VirtualBox and Windows 7 are on the same subnet because I can successfully ping the other from each side. </p> <p>I'm fairly certain that I opened port 3306 correctly on the windows side also, but I have no idea how to check if that's the problem or not.</p> <p>What else should I be doing to get the code to connect to the MySQL db?</p> <p>EDIT: The problem was that the port was not open for remote connections. After I opened the port I got the error message stating I was not allowed to connect to the sql server. From there I created a new user on the Windows MySQL with the username "home" and password "home" and was able to connect to it using:</p> <pre><code>$ mysql -h 192.168.1.9 -u home -p </code></pre> <p>However, when I run my file, which now reads:</p> <pre><code>$dsn = 'mysql:host=192.168.1.9;dbname=finance'; $db_username = 'home'; $db_password = 'home'; </code></pre> <p>I still get the 'database error' Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload