Jump to content

Recommended Posts

Posted

This is about as newbie as a question gets, but here goes. How do I connect to my database in PHP if the username is "username" and the password is "password"? And where can I find my server name? I tried finding tutorials, but most of them didn't seem to work for me.

Posted
  • Go to http://stevie.heliohost.org:2082/frontend/x3/sql/index.html
  • Under "create new database" type database name. Example: database
  • Note the database name starts with your username and an underscrore: Example: vordar_database
  • On the same page scroll down to "mysql users" and create a new user. Example: user
  • Note that the database user starts with your username and an underscore: Example: vordar_user
  • On the same page scroll down to "add user to database".
  • Select the database you created in step 2, and the database user you created in step 4.
  • Click "add" and on the next page check all the permissions your database user needs. If in doubt just select all permissions. (You can change this later.)
  • Go to http://stevie.heliohost.org:2082/frontend/x3/sql/PhpMyAdmin.html and select your new database in the left navigation panel.
  • Under the "create table" header enter "data" in the "name" box, "1" in "number of columns, and click go.
  • In the name column type the name of your new column, and then click save. Example: column
  • In the left navigation panel locate vordar->vordar_database->data->columns->column or whatever values you used.
  • Click the "insert" tab along the top.
  • In the value boxes enter some integer data like "1, 2" and click the bottom go button. Then click go again in the bottom right.
  • Go to http://stevie.heliohost.org:2082/frontend/x3/filemanager/index.html?showhidden=1&dir=/public_html
  • In the top left click "new file" and select a filename that ends with .php Example: database.php
  • Note that the file is being created in /public_html this is the webroot and will show up when you go to your domain. Example: vordar.heliohost.org
  • Click "create new file" and locate the file you just created.
  • Right click your new file and select "code edit".
  • Copy/paste in the following code:
<?php

$db_host ="localhost";
$db_pass = "password"; // use a more secure password
$db_data = "vordar_database"; // or whatever you created in step 2
$db_user = "vordar_user"; // or whatever you created in step 4

// connect to database
$conn = new mysqli($db_host, $db_user, $db_pass, $db_data);
if ($conn->connect_error) {
die("Connection failed: ".$conn->connect_error);
}

// execute a select query
$sql = "select count(*) from data";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$count = $row['count(*)'];

echo $count;
  • Click "save changes" in the top right corner.
  • Now to execute your code go to your domain in a browser, and click the filename from step 13. Example: vordar.heliohost.org/database.php
  • If you did everything right your browser should say "2" because this how many rows we created in phpmyadmin.
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...