Vordar Posted August 3, 2016 Posted August 3, 2016 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.
Krydos Posted August 3, 2016 Posted August 3, 2016 Go to http://stevie.heliohost.org:2082/frontend/x3/sql/index.htmlUnder "create new database" type database name. Example: databaseNote the database name starts with your username and an underscrore: Example: vordar_databaseOn the same page scroll down to "mysql users" and create a new user. Example: userNote that the database user starts with your username and an underscore: Example: vordar_userOn 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: columnIn 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_htmlIn the top left click "new file" and select a filename that ends with .php Example: database.phpNote 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.orgClick "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.phpIf you did everything right your browser should say "2" because this how many rows we created in phpmyadmin. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now