How To Connect to MySQL Using PHP

How To Connect to MySQL Using PHP


ABCO Technology prepares a short video for students on how to connect to a MySQL Database using PHP Code
Closed Caption:

hi this is a sample recording from aapko
technology today I'm going to show you
how to connect your database using PHP
code we're using the mysql database
which it goes it well in hand with most
PHP based websites when you're creating
a interactive website it is important
that you basically connect to the
database not only from the code but also
you connect to the database on every
page so any page that's going to
retrieve information from the database
or send information to the database
needs to have a connection to the
database now you can see here that I
have created a sample database called
block tastic which is for blogs and
there's a few tables here and i'm going
to go ahead and create to the p right to
PHP code to connect to this database
database is located on a local host the
name of the database is blog tastic
there on your PHP as part of your
convict that PHP files so whenever you
create a web based application is
important that you create a a basic
configuration file within which you
enter all the variables that you're
going to use throughout the website this
way if you ever make a change you can
easily go ahead and just make that
change in one place rather than making
the change in 30 places if you make over
an application that you're probably
planning to sell to other companies then
they can also just go ahead and change
the name according to whatever their
settings are in one place and changes
reflected this is what we call it
scalability and it's very important when
you're creating websites because
technically a website is never complete
and you need to change it from time to
time anyway moving forward
one of the things you you you do want to
is is basically go ahead and make sure
that you import the privileges so i'm
going to go ahead and click on the
privileges
tab here and privileges is where you
create a user for each application you
need to create a user for yourself i'm
going to go ahead and create route but
you can always click on add a new user
and Grantham the appropriate privileges
so that they can access that particular
database so here we're going to go ahead
and start again the databases block
tastic it's being hosted on localhost
with the user root and the password
password so once that's done you can go
ahead and use any standard HTML editor
and i'm going to go ahead and create the
very first file for this blog
application which is going to be a PHP
file and I'm going to go ahead and
select PHP here and click create once
the new file is is created it
automatically has some HTML but since
it's all going to be in PHP i can go
ahead and delete everything now the
first thing i want to start out with is
by clicking on starting with the PHP
delimiters which marks the beginning and
ending of PHP and I like this thing in
green viewer which is the text editor
that i'm using you can use any other
text editor or any HTML editor that like
textplus or coffee HTML you know but
this will deliver not only suggest the
options of a function but also if you
have as you're typing if you don't put
the right syntax dreamweaver we'll go
ahead and and point out to you the error
so you can automatically look at all the
errors as you're typing or correct them
as your timing so once you've entered
the PHP delimiters always start with the
proper comments so here I'm going to go
ahead and enter a comment that define
the variables for the database
so for the database we need for
variables the first variable is going to
be dollar DB host which is going to
which in my case is localhost you will
have to type either the the fully
qualified domain name of your server or
you can use localhost if your code and
the databases on the same server which
in most smaller websites using PHP and
mysql that is usually the case then we
go ahead and start with entering the
next variable which is a dollar DB user
and this one I'm going to go ahead and
type route
please make sure that on a professional
website you don't use root because
otherwise you're you're getting routed
the main administrator of a mysql
database if you use that then it can get
into the wrong hands and sometimes we
caused a huge problem so as part of a
security risk you should always create a
different user and and said that as user
avoid using words like root or admin or
super in your usernames because that's
what usually were people look for
hackers look for that so moving further
we're going to also define the password
here which in my case is the password
for dollar db's and then the fourth the
fourth icon that we're going to use here
is the name of the database because on a
standard my still database there can be
many different databases so we have to
specify which particular database we're
using so i'm going to go ahead and type
dollar DB database and we're going to
call that block tastic the whole name
has been created as it's a fantastic
blog so block astok
so moving further before i connect to
the database i like to specify a few
other variables that should be part of
the config file so other site related
variables also make sure that whenever
you're quoting in any any language
remember you yourself will not remember
what your code is so it's very important
that you write appropriate comments
otherwise six months later when you want
to make a change and you come back to
the same website then you will realize
that you yourself is not able to
understand your coat so proper commons
will always help you and the best part
is that if the user is our visitor tries
to view source on your side they can see
your comments anyway so moving further
i'm going to go ahead and define our
site name because I'm I usually call
that the config SATA underscore site
name and i use this as a header so i'm
going to call it the ultimate blog
once that's completed the other 1i want
to do is specify the base URL because a
lot of times you will be needing this
one so we'll call this the base URL just
as a small tip when you create a login
page if a user logs in correctly then
you would want to direct them to the
homepage and that's where you would use
the config base URL instead of the full
URL so that's where you type the four
URL of your website including the http-
right now a sample so I'm just doing
localhost / projects / blog testing
so these are mainly the variable now the
last 1i want to do for the search engine
is provide the site author so I'm going
to just looking figure underscore author
so it's always good to know who the
author of the situs you can put this
information in the footer of your file
so that's done now we provide the
functions so functions to connect to the
database so the first function that you
want to pro connect to the database is
called my sequel connected as three
options the first option is the name of
the server the second option is the name
of the username to log in and the third
option is the password please remember
that your site each time that it connect
it each time it wants to retrieve
something from the database or send
something through the database this the
application or the website has to log
into the database and that's the reason
what we need is a handle and this handle
will be used by the application to
connect now some books and documentation
will call it handle but I I usually
prefer a dollar DB so i'm going to go
ahead and provide dollar DB equals mysql
underscore connect and notice that this
is another thing as you can see here
that dreamweaver has automatically
provided the three required option which
is the name of the server than the
username and the password but since we
have already specified those in
variables above i'm just going to use
the variables here separated by commas
and the first option is dollar DB host
the second option is dollar DB user and
the third option is dollar DB password
once i'm done with that i'm going to go
ahead and close the parentheses and put
a semicolon and I'm done
now if i want i can go ahead and put a
check here
so what i can do is go ahead and see if
not dollar DB now usually because the
function the value of dollar DB return
would be true or false
so here in PHP instead of seeing if
dollar DB equals true or if dollartv
equals false you can just go ahead and
say if dollar DB riches equivalent of
saying if dollartv equals false and
equals true or you can put an
exclamation which is the same as saying
if dollar DB equals fault so here we go
and we go ahead and put a opening and go
a few steps down and then closing I
always do that i put the opening and
closing brace so that I'm not worried
about when it opens or forget something
and then of course dream we will keep
giving me errors if I don't close it so
here I'm going to go ahead and basically
here i can go ahead and type the dollar
DB equals if not dollar DB than i can
say a coal not connected to the database
so this automatically helps me basically
know if the site is not connected to the
database now sometimes what can happen
is your server may be unavailable or
something else could be the problem now
just so that my screen fits into the
camera i'm going to go ahead and move
the window and and scroll down
so we can all see what i'm typing so we
go here and I'm just going to go ahead
and hit enter a few times and this way
this part of the screen comes in here so
now this will automatically let us know
we don't need anything else and now so
if we don't get this information then
you can go ahead and move to the select
DB now also bear in mind that instead of
echo you could you could use dye which
is another option but for beginners i
would prefer that they start with echo
then the next one is where i'm going to
basically called DB connect had DB
select i'm going to call it D be
selected and this one is where we are
going to select the database so that's
my SQL underscore select underscore DB
and again you'll notice that this one
has to option
the first one is the name of the
database and the second one is there is
the option is the optional option which
is the handle which in our case is going
to be dollar DB so here the name of the
database will scroll up and we'll see
that we created a variable called dollar
DVD database so we're going to go ahead
and use that dollar TV database comma
and dollar DB which is the handle which
is also required now once again if you
want you can go ahead and run in his
statement to do that but i'm not going
to do that because I think these lines
are sufficient and that marks the end of
this config file the last thing that I
want to do is go ahead and save it I'm
going to go ahead and save it as config
dot PHP within within my existing 1i
already have a previous conflict sample
so i'm going to go ahead and see that
seemed would you like to write this fall
yes
so this is your main config file you've
defined all your variable
are you connecting to the database here
now any pages that you create for your
website what you can do is is add this
config file using the included function
which is include and then in parentheses
but config.php as the argument or you
can use it as require config.php so
whenever I create an application this is
the first step that I do and then we
begin recording of other pages this was
a part of our PHP Advanced Course at
advocate technology in which we had deep
within which we train our students and
make them develop six different
applications in class so the advanced
PHP is not just teaching some advanced
functions but actually making you create
six different applications if you are
interested you can go ahead and call our
main line at 310 216 3067 or you can go
ahead and visit our website at appt
www.eddecosta.com feel free to comment
on this video so that I can really get a
good feedback and in the future prepare
better videos so hope this was helpful
for everybody and you know feel free to
contact us if you if you have any
questions
have a nice day

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

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.BRBR License InformationBRBR 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 ...


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

This video will discuss how to create a database using PhpMyAdmin and connect to that database using PHP- mysqli. Syntax is discussed as well as some best practices. There a re many outdated tutorials which use mysql - these should not be used interchangeably. hr / bClosed Caption:/b hello and welcome in this video I'm going to cover how to connect to my sequel database using PHP and so you can see I'm using xampp here i'm just going to work off ...
Video Length: 06:41
Uploaded By: Ken Swartwout
View Count: 394,651

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

Access your databases through command line, instead of user graphical user interface. hr / bClosed Caption:/b hello youtube today i'm going to show you how to use my secret base on command line and we are also going to look how to connect the database through command line CMD after that we are going to create a database through command line when you install some this program here it's normally create the beam for ...
Video Length: 07:31
Uploaded By: Teach-the-World InfoData
View Count: 105,155

Export Access Database to MySQL
Export Access Database to MySQL

In this tutorial, I show how to connect MS Access to MySQL vis ODBC. Then I explain how to export date from Access to MySQL. hr / bClosed Caption:/b alright so in this video I'm going to show you how to establish connection between Microsoft Access and my sequel and then extract an access database to bicycle you want to start off by downloading the odbc drivers make sure you download the latest one which is 3.5 1.30 and then ...
Video Length: 02:55
Uploaded By: Michael Herman
View Count: 69,724

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

this tutorial will show you how to enable access to your MySQL server so other could manage it with a GUI :). For more information please check my blog at http://bjtechnews.wordpress.com or follow me @BJTechNews. hr / bClosed Caption:/b hey guys welcome to bj technews episode 19 and today I'm going to show you guys how to enable remote access to your my secret server on the Windows platform ok so i have two machines that have mybr ...
Video Length: 06:23
Uploaded By: BTNHD
View Count: 63,681

Connecting MS Access to MySQL
Connecting MS Access to MySQL

Demo on connecting MS access as a client to MySQL server hr / bClosed Caption:/b alright so welcome people back to I plans of technology- poor vast and onion soubise shall be demonstrated hold with three degrees on was thinking you need to rest the microphone on settings for driver great so like we said we're going to be continuing to show all we wanna have a web server running so I've already have one installed and as ...
Video Length: 11:08
Uploaded By: Paul Bastien
View Count: 49,488

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

Follow this easy step by step tutorial to learn how to open MySQL database in Microsoft Access, through an ODBC connection. Don't forget to check out our site http://howtech.tv/ for more free how-to videos! http://youtube.com/ithowtovids - our feed http://www.facebook.com/howtechtv - join us on facebook https://plus.google.com/1034403827176... - our group in Google+ It can be needed in many situations to link our MySQL database to any other database, ...
Video Length: 01:57
Uploaded By: Internet Services and Social Networks Tutorials from HowTech
View Count: 47,574

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 hr / bClosed Caption:/b hello guys when once again in the last video i have shown you ...
Video Length: 15:38
Uploaded By: ProgrammingKnowledge
View Count: 40,819

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

This video demonstrates how to install and configure the MySQL ODBC driver on a Windows-based PC and then use it to connect either Microsoft Access or Open Office Base to a MySQL database. Part 1 of 2. hr / bClosed Caption:/b hello and welcome in the short screen movie im gonna show you how to connect to a my sequel database from access using ODBC or the open database connectivity API the first thing you need to do is install the ...
Video Length: 09:53
Uploaded By: Bruce Fulton
View Count: 37,721

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

In this tutorial I talk you through installing and configuring a MySQL server to allow remote access on Linux using CentOS 6.3. So first, download and install the mysql server: yum install mysql mysql-server Next make it so as the mysql server with be running on server startup, issue the following command: chkconfig mysqld on Next start the mysqld service service mysqld start Next run the command ...
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

Please subscribe for more video tutorial VB.NET with mysql (insert, delete and update) VB.NET with ms access (insert, delete and update) VB.NET with mssql (insert, delete and update)
Video Length: 02:43
Uploaded By: Stephen Pacaldo
View Count: 28,286

Copyright © 2025, Ivertech. All rights reserved.