PHP Tutorial for Beginners 30 # How to connect to MySQL database using PHP

PHP Tutorial for Beginners 30 # How to connect to MySQL database using PHP


PHP Connect to the MySQL Server
connecting to mysql database php
android connecting to php mysql
How to access a MySQL database with PHP code
How to Connect to MySQL From a PHP Document
3 Ways to Connect to MySQL Using PHP
MySQL Tutorial - Connect
PHP/MySQL Tutorial
Connect to Your MySQL Database using PHP
PHP Connect to the MySQL Server
Closed Caption:

hello guys when once again in the last
video i have shown you how you can
create your first
mysql database using PHP myadmin now in
this video we are going to see how we
can connect to this my school database
using our PHP script
so let's get started I have this blank
while so i will save this file first and
i will save it as
so in here
i'm going to create one more first of
all go back
create a folder and I've database
ok
and in this database i'm going to create
a file called connect . b HB
so this will be a file which we are
going to use to connect to our MySQL
database and then we can include
required this file and other files so
that we have the connection with the
data is right
so in order to connect to the database
you need three parametres first is so
over name or my skill hostname first of
all second is username which is my skill
username and third is my school password
so when you go to your PHP myadmin here
and click this icon PHP my admin and you
will be able to see this users tab here
and in here you will be able to see the
privileges
so we are going to connect to the user
called the root and the host is
localhost right now and the password is
the same password you have said when
that you have installed this damp
- right so our whole user is root and
horse neighs localhost right so we go to
our PHP file and inhale we are going to
declare my SQL
underscore and this will be our host
ok and this will be equal to localhost
ok you can change this to the IP address
of your server or you can change it to
127 . zero . zero . one
it's the same as local host ok now
second thing I will define it as my SQL
and this will be our for example user
and the user is in our case
user is root right in here
when you see here
so its throat and once again we will
define a variable called my SQL
underscore password
ok and this will be whatever password
you have set so i set a password when I
installed my school that was good but
whatever was your password when you have
installed Sam and on when you set my
skill in my in the security you have
said some password right just so so the
same password you need to give here in
my skill securities
now we are going to connect to the
database
so what we can do here is we can use an
inbuilt function called my SQL on the
school
connect ok this will be the function and
in here we need to pass three parameter
first is the hostname second is the
username and third is the password
so the first argument will be the host
name , second argument will be the
username and the third argument will be
the password
ok so and everything goes well we can
echo called success for example or we
can go connection success
not here but here
ok i will save it and i will open up my
localhost and I'll search for local host
here and here i have database folder and
in here i have connection . PHP right
I'll open it and it will say connections
axis that means I'm connected to the
database right
now for example you provide some wrong
information for example this user name
instead of this user you can provide
some random random user
ok save it and once again won it and you
will be able to see this error
it's saying that access denied for this
user because it's not registered right
so you need to give the same username as
here and am host as here and the
password you have set
ok otherwise it will give an error but
if you can see if you see here this is a
kind of a header of warning it's giving
and for example you want to define your
custom error
how you can define a custom matter you
can just I will reward
this changes and i will say after this
my school function i can say are dying
and what this all died
- is it will kill your page after if it
towards an error
so when you're my school connection is
not okay
it will kill your page and this die also
takes a argument and this argument or
you can provide some message
let's get your message can be you can
not connect to our database
ok and then i will save it and let's
provide some random username to check
whether it throws this error or not
so once again and refresh it and you can
see here cannot connect to the visit
cause this error when the user when my
school connection is not okay but then
you are seeing this error right
this morning kind of thing to remove
this warning
you can just add our ad the rate symbol
before your function
ok so this kind of a great symbol when
you include being you move your warnings
and you will be able to see only that
however you want to show ok so once this
is done what we can do is we can once
this is the connection to the server but
we need to select our database from the
server my school server right so we have
some more
some databases in this my school so
right
and in the last video we have created
the student database right so select
this and this was the student database
and when I go to this table here
I could be created this table userinfo
inside my a student database and it has
some data right so what i can do is i
can connect to the same database called
student from this by using a function
and i will use at the rate to the more
warnings if it gives and i would say why
as you wear underscore select DB
ok and here you can give the name of
your database
ok why didn't the best name is in here
you can see why did his name is student
you can give you own data obviously
student
ok so once you're connected to the
server you can connect to the database
and then you are ready to ready the DWS
right but this is kind of you know whose
approach to connect to the database
because of once this throws an error
there's no meaning of calling this
function right so what we can do here is
we can just select our if condition
so you can write if and in the bracket
posted online to this and in the bracket
what i can do is i can pass this
function because this function returns a
boolean value and boolean what is
invalid can either return true or false
ok and from if condition we compare if
it really does true and if the function
is done stool we can perform the
statement inside this implementation so
i'll just copy this function here and
returns true and i will also use this at
the Ritz and blue
so if it returns to or i can say if it
is not connected i will show an error
some kind of an error
so it residence halls
I can say that well this message I can
Diane I can just give this message it so
you can just give this message when you
die die means killing the page
ok the same you can do it with the
function called exit exit and I are seen
ok so you can either use die or exit
both words like Sam it will kill your
page
ok so if I'm not connected to server I
will die as i can show this message
which is a connection success
ok but still if I connected to the
server
I need to connect to the database right
so i can give one more condition here if
I am connected to the student database
here and this ship is for example i take
if not connected
so we give this not connect to symbol I
can see that now i will die again else
I will do nothing ok so I'm checking
whether i'm going to do so on and I
don't need these lines now i will remove
this
so this is my code if I'm not connected
to the server then i can say connection
success or if I'm not connected to the
server
I can throw this message which is the
connection of connection or cannot
connect to the database right or if I'm
not are connected to the database
I can throw this message white or and
blowing it a little bit wrong
yes so this should be here in the else
condition because here I'm checking if
I'm connected to the database and if I'm
not connected
I will throw an error and if i'm
connected i have go to the else
condition and i will check one more
condition which is if I am connected to
the student database right and then if I
am connected to the student database
then I wish I will show this message
connection successful they should be and
connections and I we're not checking
false but for the true connection then
we can see connection successful else we
can see cannot connect to the database
right
ok i will make it a little bit smaller
so that you can see all the board and
let's check this once again working the
browser check it and its citizens cannot
connect to the database
why let's see because our username is
root 1 which is not the real accuser are
real loser
user is root
right if you can see here in the
privileges or user
we have musical the route localhost and
the possible so i will save this and
once again i had a freshness and now it
says connection success
ok so in this way you can connect to the
line is cool database using your PHP
script right now in the next video I'm
going to show you how you can
ready you are a database to get the
database values for example want to get
those values which are there in the
database table all the this table we
have created user input into right and
we have some data in that so I want to
patch that data from the database in my
PHP forum so high up and I do this
actually in the next video so stay tuned
and please rate comment subscribe and
bible ah

Video Length: 15:38
Uploaded By: ProgrammingKnowledge
Published: 8/10/2014
View Count: 105,913

Related Software Products
Access-to-MySQL
Access-to-MySQL

Published By:
Intelligent Converters

Description:
Access-to-MySQL is a program to move MS Access databases to MySQL server. All MS Access data types and attributes are supported. The program works with Unix and Windows MySQL servers. License Information Single-User License allows clients to install the software product on exactly one (1) computer system. Client can store a backup copy of the software but cannot use two copies of the software at any one time. Single-User License does NOT allow to make use of the software through a corporate ...


Related Videos
Connect to MySQL with PHP in XAMPP / Create a new database
Connect to MySQL with PHP in XAMPP / Create a new database

Video Length: 06:41
Uploaded By: Ken Swartwout (12/11/2013)
View Count: 1,972,641

How to connect to Mysql database through windows command line (cmd)!
How to connect to Mysql database through windows command line (cmd)!

Video Length: 07:31
Uploaded By: Teach-the-World InfoData (8/8/2014)
View Count: 510,012

Export Access Database to MySQL
Export Access Database to MySQL

Video Length: 02:55
Uploaded By: Michael Herman (11/15/2012)
View Count: 170,935

Episode 19 - How To Enable Remote Access To MySQL Server on Windows Server
Episode 19 - How To Enable Remote Access To MySQL Server on Windows Server

Video Length: 06:23
Uploaded By: BTNHD (6/13/2012)
View Count: 159,161

How to Open MySQL Database With MS Access
How to Open MySQL Database With MS Access

Video Length: 01:57
Uploaded By: Internet Services and Social Networks Tutorials from HowTech (5/30/2013)
View Count: 108,338

How To Connect to MySQL Using PHP
How To Connect to MySQL Using PHP

Video Length: 16:20
Uploaded By: ABCO Technology
View Count: 91,181

Connecting MS Access to MySQL
Connecting MS Access to MySQL

Video Length: 11:08
Uploaded By: Paul Bastien (5/15/2012)
View Count: 78,916

Connect Access / OOBase to MySQL Using ODBC Part 1 of 2
Connect Access / OOBase to MySQL Using ODBC Part 1 of 2

Video Length: 09:53
Uploaded By: Bruce Fulton (7/30/2008)
View Count: 38,609

MySQL - Remote Access to MySQL Server on Linux CentOS 6.3 Part 1
MySQL - Remote Access to MySQL Server on Linux CentOS 6.3 Part 1

Video Length: 17:05
Uploaded By: David Does Programming
View Count: 31,119

Import csv file to mysql database using workbench
Import csv file to mysql database using workbench

Video Length: 02:43
Uploaded By: Stephen Pacaldo
View Count: 28,286

Copyright © 2026, Ivertech. All rights reserved.