I created an SQL database.
DB_name: id1360365_stuff
DB_user: id1360365_stuff
DB_host: localhost
PW: stuff
I found a tutorial on how to connect to a SQL database using PDO:
https://www.bitdegree.org/learn/mysql-create-database
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE DATABASE myDBPDO";
// use exec() because no results are returned
$conn->exec($sql);
echo "Database created successfully
";
}
catch(PDOException $e)
{
echo $sql . "
" . $e->getMessage();
}
$conn = null;
?>
There are four variables I need to get right:
$servername = “localhost”;
$username = “username”;
$password = “password”;
dbname= MyDB
I assume these need to be adjusted: so I did:
$servername = “localhost”;
$username = “id1360365_stuff”;
$password = “stuff”;
dbname= id1360365_stuff
This doesn’t run even inside basic html/body tags.
I have tried what seems to be every possible permutation of the above information, even swapping out 000webhost passwords. Please help!
Do I have CREATE privileges by default?
Can you explain what you are doing?
You can only create databases via 000webhost.com on Manage Database page.
I created a database:
DB Name DB User DB Host
id1360365_qwerty id1360365_qwerty localhost
I tried to access the database using a PHP script and it failed (above).
I tried several other PHP scripts and they could not connect to the SQL database.
How to connect my PHP scripts to the SQL database?
Introduction
You can create databases on 000webhost.com and PHP can be used to connect to those databases. This tutorial explains three different methods how that could be achieved. Most of the websites need to have at least one database and if you are developing a website from the beginning you will have to connect it to a database manually, here you can find how that could be done step by step.
What you'll need
Before you begin this guide you'll need the following:
Understanding of PHP …
Does that help?
You are running these scripts on your 000webhostappurl yes?
You CANNOT run these scripts LOCALLY on your PC for example saved in a file.