• Home
  • Technology
    • Ebullientech
    • Entrepreneurship
    • Video Technology
    • Cloud Computing
    • Business Analysis
  • Healthcare
    • Pharmacology
  • Thoughts
    • Food
    • General
    • Stories
    • Places
    • Workplace
    • Social Issues
    • Reviews
  • Quotes
  • Ebullientech News and Events
  • About

Kamalika's Notebook

thinking nothing...............!!

You are here: Home / Kamalika / Technology / MySQL / How to connect to MySQL database using PHP

How to connect to MySQL database using PHP

August 21, 2014 By Kamalika Leave a Comment

Create a database and table in MySQL

Simply hit http://localhost in your browser, it’ll redirect you to the URL http://localhost/xampp, look for phpMyAdmin under Tools menu in the left, click on phpMyAdmin, it’ll take you to the MySQL Administration interface which is developed using a free and open source software called phpMyAdmin (most downloaded application in SourceForge). Change the language to English under Appearance Settings if it’s already not English. Click on Databases menu from top left in the middle panel (just below localhost icon). Type the name of your database in Create Database text box, I’ll name it as bittu, don’t change anything in the collation box. Hit Create button. Select your database from the left panel by clicking on it you’ll see the option to create table, you can either use the interface to you create table and fields in the table or you can use a SQL QUERY. Construct the QUERY and paste in on SQL box, hit Go button. I’ll rather write a QUERY because that is a faster method to create a table. Below is my SQL QUERY.

[bash]

CREATE TABLE `users` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(50) DEFAULT NULL,
`lastname` varchar(50) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`pssword` varchar(32) NOT NULL,
`created_time` timestamp DEFAULT CURRENT_TIMESTAMP,
`active` tinyint(3) DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

[/bash]

Bingo! You have created your first MySQL database table. Now lets enter some data into it. Again you can use the phpMyAdmin interface to enter data into the table or you can use SQL QUERY. I’ll use SQL QUERY.

[bash]

INSERT INTO `users`(`uid`, `firstname`, `lastname`, `email`, `pssword`, `active`) VALUES (”,’Bittu’,’Sharma’,’bsharma@xyz.com’,MD5(‘admin’),’1′);

INSERT INTO `users`(`uid`, `firstname`, `lastname`, `email`, `pssword`, `active`) VALUES (”,’Kamalika’,’Roy’,’kroy@abcd.com’,MD5(‘admin123′),’1’);

[/bash]

We have successfully entered two records / rows into the table. Next step is to fetch / retrieve this data from the table using PHP code.

Pages: 1 2 3

Filed Under: MySQL, PHP, Technology Tagged With: Connecting to MySQL using PHP, How to use PHP to connect to and retrieve data from MySQL, PHP & MySQL, sample php code to connect to mysql database

« Write your first PHP program…
What is a CMS…and WordPress »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

Let’s connect…

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Hello There…

I'm Kamalika, a techpreneur & startup mentor, blogger, hobbyist photographer, Netflix & Kindle indulgent, food connoisseur, Starbucks aficionado and former Disney employee ...next

Looking for something?

Tags

All in One SEO Pack AWS Banaras Blogger Blogging Blogs Dasaswamedh Ghat Ebullientech Ebullientech Interactive LLP Facebook Facebook Developers father's day father's day wishes father's day wishes for dad fathers day love Fathers Day Special Fathers Day wishes from daughter Father’s day memories GeoTech GeoTech Informatics HipHop for PHP Kamalika Guha Roy Kashi Ganga LAMP MySQL Nabaneeta Guha Roy Online Marketing PayPal PayPal's suspension of Indian bank transactions PHP PHP & MySQL Saraswati Puja Search Engine Optimization SEO Startup The Ganges TypePad UCO HUT Varanasi Web 2.0 Web 2.0 Design Web Design Web Marketing WordPress WordPress.COM

Timeline

  • 2024 (1)
  • 2021 (3)
  • 2020 (7)
  • 2019 (4)
  • 2018 (1)
  • 2015 (6)
  • 2014 (13)
  • 2013 (9)
  • 2010 (7)
  • 2009 (2)

Topics

Copyright © 2021 · Kamalika Guha Roy, Powered by: Ebullientech