Php code to connect to mysql Database.

Connecting to mysql Database in php  three variables need to be specified.These are mysql server address- normally,when connecting to a m...

Connecting to mysql Database in php  three variables need to be specified.These are

  • mysql server address-normally,when connecting to a mysql database hosted locally you should use   localhost or as  the server address.
  • username-mysql server has a table called users which stores passwords and username for people allowed to connect to the database.
  • password-every user connecting to mysql database needs to have a password.
Below is example of a code that connects to a mysql server hosted locally.

 $host="localhost"; // Mysql Server Host name/address  
 $username="root"; // Mysql username root   
 $password=""; // using no password  
 $link=mysql_connect($host,$username,$password) or die(mysql_error());//assign the connection a variable   
 //once the connection is the database to use.  
 mysql_query("SET names UTF8");  

Once you have connected to the Mysql server,you need to select the database to use and set mysql_query as UTF8.

Its advisable to save the connection code to the server as a separate file to avoid repeating the same code whenever you want to connect to the database in different pages. i.e

Save the connection file as connect.php

and whenever you want to connect to the database,just include the file in start of the next page using require() function

 require 'connect.php';  



android android Apps android emulators antivirus arrays blogger bluestack Break Statement in Java constructors download downloader drivers emulators fragment java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql node.js php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
Java Codes: Php code to connect to mysql Database.
Php code to connect to mysql Database.
Java Codes
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy