connectdatabase
connectdatabase
Connect a Database
1 post
Don't wanna be here? Send us removal request.
connectdatabase · 4 years ago
Text
How to connect a database to a website?
Tumblr media
Most websites need to have at least one database and if you are developing a website from the start you should interface it to a database manually. This article helps you to find the information of how to connect a database to a website.
youtube
Here you can find how that ought to be conceivable step by step.
What you'll require 
Before you start this guide you'll require the accompanying: 
Understanding of PHP syntax 
Access to your 000webhost.com account and reports 
Database created on 000webhost.com account 
 Stage 1 — Creating a PHP report 
 You need to create a PHP report (with .php expansion) on your PC and upload it to the specialist. It's just a basic new report created on your PC which has a .php expansion. Here is a tutorial about doing that on Windows framework using Notepad: Creating PHP record 
 Stage 2 — Uploading the record created 
 You should navigate to the archive manager of 000webhost now and upload the record created. On your control panel press Upload records and then Upload reports now. 
 At whatever point you are redirected to the File Manager press the control buttons and select Upload records as given in the screen capture beneath. 
 At that point, you need to pick the necessary record on your PC and press the Upload button. 
 Stage 3 — Editing the PHP archive 
 As of now, you need to alter the uploaded report. It may be done straightforwardly on the File Manager. Press the right mouse button on the uploaded archive and select alter. 
 The archive should be altered depending upon the association procedure. If you are enthused about contrasts between these strategies you can read more here 
 Method 1 — Connecting to the database using PDO (recommended) 
 <?php 
 $servername = "localhost"; 
 $username = "username"; 
 $password = "password"; 
 $database = "database"; 
 attempt { 
 $conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password); 
 /set the PDO botch mode to special case 
 $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
 reverberation "Associated viably"; 
 } catch(PDOException $e) { 
 reverberation "Association failed: " . $e->getMessage(); 
 } 
 ?> 
 Procedure 2 — Connecting to the database using mysqli (Object-Oriented) 
 <?php 
 $servername = "localhost"; 
 $username = "username"; 
 $password = "password"; 
 $database = "database"; 
 /Create association 
 $conn = new mysqli($servername, $username, $password, $database); 
 /Check association 
 if ($conn->connect_error) { 
 die("Connection failed: " . $conn->connect_error); 
 } 
 reverberation "Associated viably"; 
 ?> 
 Strategy 3 — Connecting to the database using mysqli_connect (Procedural) 
 <?php 
 $servername = "localhost"; 
 $username = "username"; 
 $password = "password"; 
 $database = "database"; 
 /Create association 
 $conn = mysqli_connect($servername, $username, $password, $database); 
 /Check association 
 if (!$conn) { 
 die("Connection failed: " . mysqli_connect_error()); 
 } 
 reverberation "Associated viably"; 
 ?> 
 Stage 4 — Making the necessary changes 
 On all the procedures you need to alter three lines essentially because 000webhost utilizations localhost as the laborer name (specialist name should not be changed). 
 Username - The username assigned to the database. It will in general be found on your 000webhost control panel - > Manage database. Username is consolidated of your 
 000webhost username and the name you created. 
 Password - a password that you set for your username of this database. 
 Database - The name of your database. It may be found on your 000webhost control panel - > Manage database. The database name is gotten together with your 000webhost username and the name of the database you created. 
 Stage 5 — Testing the PHP association 
0 notes