Search the Knowledgebase | 
		 Browse by Category | 
	
	
		| 
			
		 | 
		
			
		 | 
	
	
		| 
			
		 | 
	
	
		| How do I connect to my MySQL database with PHP? | 
	
	
		
			
				
					
					
						| 
							Article Details
							 Last Updated 17th of June, 2008 
							
						 | 
					 
					 
				 
				
				
					
						
							| User Opinions (7 votes) | 
						 
						
							
								
71%
 
28%
 
							 | 
						 
					 
					 
					
					
						
							| 
								Thank you for rating this answer.
							 | 
						 
					 
				 
			 
			 
	Here is a quick description of what commands are needed in your PHP pages to connect to MySQL. Note that if you need to connect remotely from another machine, you must let us know the IP# you will be connecting from so we can enable this for your database. 
		
	
		1. Connect to the MySQL Server 
			
					
				Use the following statement to connect to the database server. Substitute the username and password for your MySQL username and password. 
					
				mysql_connect('localhost','USERNAME','PASSWORD'); 
			 
				
			2. Select Your Database 
				
			
				Use the following statement to select the database you wish to connect to. Make sure you substitute your database name for the example. 
					
				@mysql_select_db('DATABASENAME'); 
			 
				
			3. Executing A Query 
				
			
				You are now ready to execute your queries. (Most problems that arise with your scripts will be due to incorrect permission settings.) 
					
			 
				
		 
 
 
 
		 | 
	
	
	
	
	
	
		| Attachments | 
	
	
		| 
			No attachments were found.
		 |