How to Connect PHP to MySQL Database using XAMPP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to solution : in this video we are going to see how to connect to MySQL database using PHP so let's start first of all the initial requirement is you are required to have some server like in my case I have zamp as a server so you can download the samp from the official link of zam which I am going to paste in my description section once you have installed zamp you just have to open Sam control panel oh you can open this by going inside the C Drive Zam folder and the control just here right double click you will see this and you have to just start the service like Apache and MySQL also ok here are two services running so I'll just close one or you can just start it by typing like it will search for you Sam okay here you will see the control man and you can start Sam service from there also so this is the initial requirement for writing PHP and a code editor in which you are going to write PHP code so I prefer it to use notepad plus plus to write PHP coding because I like it okay and it's you can see that the PHP syntax is turned red so it is easy to make out the key words and all using notepad okay so we are here to learn how to connect to the database using PHP script okay so for that we need to create a database so first of all let's see whether our localhost is running or not press ENTER and see whether it's running or not if you don't see this you are having some errors in it so you need to fix out those for that I'm going to the most common error in zam is the error of the passwords okay so I'm going to put an annotation or a link in the description for that if you don't say this you must see that video first to get start with PHP and zam okay now first of all we need to create a database in order to connect to it so we will just create a database okay here you see a new give it so you can give your database any name I will give it a solution cone and I will just create it so inside your solution cone we have to create a table so we just create a table underscore SC okay this is a table name and the call number of columns I will but it is three and I will just hit go so here it asks for the attributes like ID it is integer and it is primary IDs are primary key okay and here it's an AI a underscore ID stands for auto increment so I want it as an auto increment it okay now the next term is like name it is a we're care and you can set the length for the name as 30 okay okay and the last thing is like address suppose I want to store the address also so I'll just hmm okay it's a 50 once you have set your database and you have created a table you are ready to go now you have to insert the values just I'll show you how to insert you can just click here like insert and it's an ID so if you want to specify it you can specify one or you can leave blank as we have selected Auto increment there so it will increment us for us okay that's why I will just leave it as blank and the names I'll give it as suppose nikhyl and the address is India and the another name is Akshay and the address is India now I will store this two values you can see that go okay so you can see this message to rows are inserted and when you go to your table you can see that those values are inserted now what we have to do is we have to write a script to connect to this to this nice-looking database okay so for that first of all what we need is a DB host what is our host in this case it is a local host okay the second thing is username if you are using zamp or RAM okay the username is root and the password is nothing password is blank but in my case I have set a password as root but in your case if you are using them for the first time you would leave it as blank okay and the next thing is just we have to connect so I'll write MySQL underscore connect and inside this connect we are going to pass this three values first parameter it takes is a DB host okay and always remember this if you don't put a double quotes here you will get an error because it is it is a variable and PHP does not understand if you don't specify a double quotation mark here okay so it is compulsion that you have to put a double quotation mark there and here it's in username second fill it take as username and the third field it will take it as a password and that's eight yes yes now let's check whether we have connected to the my sq successfully if we will see this connected in our browser that means we have connected to this okay so I will take it as localhost inside that I have a PHP folder inside that I'm just just connect dot PHP okay it's taking some time okay so you can see this message that it is connected okay so this is how you connect to the MySQL database MySQL okay now you have to go inside this step inside this database you are inside MySQL but you have to insert the values or retrieve the values so you have to be in one of these database suppose I want to insert a value in solution Cone database so I have to I have to select this database from the entire database we see here okay so for selecting a database now I'll just put it as a comment I don't want it anymore I know that it's an error of record my SQL underscore select DB this is a nice little thing okay and here what we have to do is okay let's make another variable known as DB and will you give the name it as solution cone because that's our database name which we want to select okay and we'll just pass here as DB and let's see and we will just echo this thing here so if we see connected that means this is correct you can see that is connected okay connected to database so this is how you connect to your database in the next video I am going to show you how to insert values and you will learn how to insert values using PHP scripts so hope you like this video thank you for watching please like subscribe and comment below if you have any queries thank you
Info
Channel: Solution Cone
Views: 248,254
Rating: undefined out of 5
Keywords: PHP (Programming Language), MySQL (Software), XAMPP (Software), how to connect php to mysql database using xampp, Connect PHP to mysql database using xampp, Connect PHP to mysql, How to, How to Connect PHP to mysql, How to Connect PHP to mysql database
Id: EM3LsdisFSw
Channel Id: undefined
Length: 11min 48sec (708 seconds)
Published: Thu Aug 06 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.