Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

TUTORIAL: Connecting to a mysql database

Featured Replies

Ok so this might seem like an easy task for most php programmers but for beginners who are just starting out might not be able to sucessfully connect to a mysql database so i decided to write this short tutorial on it

 

Mysql_connect what it does

 

Ok so the mysql_connect function is pretty much the bread and butter of connecting to the database so first imma give you 3 simple things to remember when you look at this function.

 

1.Host

2.User

3.Password

Ok so let me explain these 3 things for you real fast Host is normally 1 of 2 things localhost or mysql on my site its mysql if ur using a testing server most always it will be localhost. Ok so lets move onto User this is the username you use to sign into phpmyadmin and password is the password you use to sign into phpmyadmin.

so in the end the connect function should look something like this

 


mysql_connect(localhost,user,'pass') or die ("Could not connect to database");

Oh and btw the

or die

statement is only called if for some reason your site can not connect to the database then it will output Could not connect to database

 

Mysql_select_db Very easy one

 

Ok so this function is basically just the name of your database so heres the example

 

 

mysql_select_db(mydatabase);

 

Lets put it all together

 

$host = "localhost";
$user = "user";
$pass = "pass";
$db = "database name";
mysql_connect($host,$user,$pass) or die ("Could not connect to the database");
mysql_select_db($db);

 

Ok so thanks for reading and i hope beginners in php have took away something useful from this tutorial :yahoo:

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.