0

I'm running a small rPi server (Apache2, php5 installed), and I was doing some research on how to display data onto a webpage from a SQL data base. So, thorough phpMyAdmin, I created a small database called "Test" using phpMyAdmin, and it has two columns (Name, Age), and three rows. I followed an tutorial on how to connect to it, and created these two files. However, I keep getting my "die" message of "Error connecting to database". Any help on what I might have done wrong would be appreciated! Feel free to request any additional details.

connect.php

$dbcon  = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); //Connect 

if(!$dbcon) {
die('Error connecting to database');
}

echo 'You have Connected Successfully';
?>

chonline.php

<?php
include ('connect.php');

$test = $dbcon;
echo $test;
?>

index.html

<html><body><h1>Raspberry Pi Test Page!</h1>
<p>If you see this message,rPi server is up and running.</p>
<p>Server Public IP: 67.164.104.19.</p>
</body>

<a href = "test.php">TableTest</a>
<a href = "chonline.php">Connection Successful?</a>
</html>
5
  • You say you created a database with two columns and three rows. Am I to understand that you meant you created a table? Commented Apr 26, 2013 at 18:56
  • have you set DB_HOST, DB_USER, DB_PSWD, DB_NAME values ? Commented Apr 26, 2013 at 18:56
  • 1
    Can you post the output of mysqli_connect_error() - also, shouldn't you use localhost as database host, I'm assuming the MySQL server is running on the rPi? Commented Apr 26, 2013 at 18:56
  • In the manual page you can find several usage examples on how to read the error message. Commented Apr 26, 2013 at 18:57
  • Maybe you haven't set the privilege to connect from your server to that IP. Commented Apr 26, 2013 at 18:59

1 Answer 1

1

Try changing

define('DB_HOST', '67.164.104.19');

to

define('DB_HOST', 'localhost');

See if that gets you anywhere.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.