주 콘텐츠로 건너뛰기
연락처
  • 월-금 6:00am -11:00pm 월요일 부터 금요일 까지.0808802111
  • 월-금 6:00am -11:00pm 월요일 부터 금요일 까지.0808802111
전화 번호 및 시간
고객센터

온라인 도움말 리소스 살펴보기

도움말

GoDaddy 도움말

Connecting to MySQL Using PHP

You can access MySQL databases directly through PHP scripts. This lets you read and write data to your database directly from your website.

  1. Connect to your MySQL server using the mysqli_connect statement. For example:
    $con = mysqli_connect('HOSTNAME','USERNAME','PASSWORD');

    For help with your mysqli_connect information, see Find your database hostname.

  2. Select the database that you want to access using mysqli_select_db. For example:
    mysqli_select_db('DATABASENAME', $con)

    Where 'DATABASENAME' is the name of your database — this also displays on your database's details page.

After establishing the connection and selecting the database, you can query it using PHP.

To help you create your own connection string, we've included an example below.

Example PHP MySQL connection string

This connect string will look in a database (your_dbusername, find a particular table (your_tablename), and then list all values in that table for a field (i.e. column) you specify (your_field).

<?php
	//Sample Database Connection Syntax for PHP and MySQL.
	
	//Connect To Database
	
	$hostname="your_hostname";
	$username="your_dbusername";
	$password="your_dbpassword";
	$dbname="your_dbusername";
	$usertable="your_tablename";
	$yourfield = "your_field";
	
	mysqli_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
	mysqli_select_db($dbname);
	
	# Check If Record Exists
	
	$query = "SELECT * FROM $usertable";
	
	$result = mysqli_query($query);
	
	if($result){
		while($row = mysqli_fetch_array($result)){
			$name = $row["$yourfield"];
			echo "Name: ".$name."<br/>";
		}
	}
?>

For more information, see the MySQL Functions page at php.net.

커뮤니티 관련

gdgdaddy's Avatar
connecting to a mysql db thru php

5 답변

Last posted over 1 year ago.

mikeb1's Avatar
Connecting to mySQL database

5 답변

Last posted about 1 year ago.

mikeb11's Avatar
Re: connecting to a mysql db thru php

2 답변

Last posted over 1 year ago.

marshun's Avatar
access denied connecting to mysql database from php

5 답변

Last posted over 2 years ago.

Britinusa's Avatar
Connecting Perl Script to MySQL

2 답변

Last posted over 2 years ago.

찾고 있는 내용이 보이지 않으시나요? 커뮤니티를 검색해 보세요.