PHP 7 mysql_connect 

WBOY
풀어 주다: 2024-08-29 13:10:48
원래의
237명이 탐색했습니다.

다음 문서에서는 PHP 7 mysql_connect에 대한 개요를 제공합니다. 개발자는 PHP를 서버측 스크립팅 언어로 사용하여 동적 웹 애플리케이션과 프로그래밍을 구축합니다. PHP5, PHP7 등 여러 버전의 PHP를 사용할 수 있으며 각각 기능과 서비스가 다릅니다. 그때 동적 프로그래밍을 해야 할 때는 MySQL과 같은 데이터베이스에 연결해야 합니다. PHP 7과 MySQL 간의 연결은 코딩을 통해 달성할 수 있습니다. PHP는 공개 연결임에도 불구하고 버전 5.5에서 MySQL을 더 이상 사용하지 않고 PHP 7에서 완전히 제거했습니다.

광고 이 카테고리에서 인기 있는 강좌 PHP 개발자 - 전문 분야 | 8개 코스 시리즈 | 3가지 모의고사

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

PHP 7 mysql_connect란 무엇인가요?

mysql_connect()는 MySQL 서버와의 연결을 설정합니다. 임의 경계가 누락된 경우 다음과 같은 기본값이 허용됩니다. 서버 = 'localhost:8080', 사용자 이름 = 서버 주기를 요청하는 클라이언트 이름, 비밀 키 = 무효 비밀 단어. 서버 경계에도 포트 번호가 포함될 수 있습니다.

mysql_connect() 작업은 지칠 줄 모르는 MySQL 연결을 엽니다. 이 능력은 진보의 연관성, 즉 FALSE와 실망의 실수를 반환합니다. 용량 이름 앞에 '@'을 추가하면 실수로 발생한 수익률을 숨길 수 있습니다.

웹 서버가 아닌 프레임워크에 XAMPP를 도입한 경우 이름을 localhost로 지정해야 합니다. 물론, MySQL 클라이언트 이름과 비밀 키는 "root"와 클리어("")로 각각 구분되어 있습니다. 하나의 기본적인 벤처를 만들어 PHP 코드를 MySQL과 연결해 보겠습니다. Windows를 사용하는 경우에는 "C:/xampp/htdocs/"에 "htdocs" 봉투가 있습니다(기본 영역에 도입될 때마다). Linux(대부분 Ubuntu)를 사용하는 경우 "/pick/lampp/htdocs"에 있습니다(수첩을 만들기 전에 루트 클라이언트로 변경해야 합니다.).

PHP 7 mysql_connect를 어떻게 사용하나요?

이제 PHP 7 MySQL 연결을 어떻게 사용할 수 있는지 살펴보겠습니다.

먼저 개발자에 따라 요구 사항에 따라 Tomcat, XAMPP 등을 설치할 수 있는지 여부에 따라 원하는 서버를 설치해야 합니다. 그런 다음 애플리케이션 요구 사항에 따라 서버를 변경해야 합니다. 다른 방법으로는 MySQL 서버와 프로그래밍 도구를 설치하여 코딩을 수행할 수 있습니다. 더 나은 이해를 위해 아래 구문을 고려해보세요.

asset mysql_connect ( [string server [, string specified username [, string user_password [, bool new_link [, int flags value]]]]])
로그인 후 복사

진행 중이면 MySQL 인터페이스 식별자를 반환하고 실망하면 FALSE를 반환합니다.

mysql_connect()는 MySQL 서버와의 연결을 설정합니다. 임의 경계가 누락된 경우 다음 기본값이 예상됩니다: 서버 = 'localhost:8080', 사용자 이름 = 서버 주기를 요청하는 클라이언트 이름, 비밀 문구 = 비밀 문구 무효.

서버 경계에도 마찬가지로 포트 번호가 포함될 수 있습니다. 예를 들어 "호스트 이름: 포트"입니다.

참고: "localhost" 또는 "localhost: port"를 서버로 결정할 때마다 MySQL 클라이언트 라이브러리는 이를 무효화하고 이를 이웃 연결(Windows에서는 파이프라고 함)과 연결하려고 시도합니다. TCP/IP를 활용하려면 "localhost" 대신 "127.0.0.1"을 사용하세요. MySQL 클라이언트 라이브러리가 허용되지 않는 근처 첨부 파일과 인터페이스하려고 시도하는 경우 PHP 디자인에서 mysql.default_host로 올바른 방식을 설정하고 웨이터 필드를 비워 두어야 합니다.

PHP 3.0B4에는 ": 포트" 지원이 포함되었습니다.

PHP 3.0.10에는 ":/way/to/attachment"에 대한 지원이 포함되었습니다.

용량 이름 앞에 @를 추가하면 실망에 대한 실수를 숨길 수 있습니다.

비슷한 인수를 사용하여 후속 호출이 mysql_connect()에 대해 이루어지면 새 연결을 배치하지 않습니다. 대신 일반적으로 열린 연결 식별자를 반환합니다. mysql_connect()의 new_link 매개변수는 함수가 이전에 동일한 제한으로 호출된 경우에도 항상 새 연결을 열도록 하여 동작을 조정합니다. 플래그 경계는 MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE 또는 MYSQL_CLIENT_INTERACTIVE 상수를 혼합할 수 있습니다.

PHP 7 mysql_connect 매개변수

이제 다음과 같이 다양한 PHP 7 MySQL 연결 매개변수를 살펴보겠습니다.

구문:

mysql_connect(
string $server_host = ini_get("get the host "),
string $specified username = ini_get("get username"),
string $user password = ini_get("user password"),
bool $new_link = false,
int $client_flags = 0
): resource|false
로그인 후 복사

설명:

위 구문을 사용하여 MySQL과 PHP 7을 서로 다른 매개변수로 연결해 보겠습니다.

  • server_host: The MySQL server. It can likewise incorporate a port number. For example, “hostname: port” On the off chance that the PHP order mysql.default_host is indistinct (default), the default esteem is ‘localhost:3306’. However, SQL experimental mode overlooks this boundary and always utilizes the value ‘localhost:3306’.
  • specified username: The username, default esteem, characterized by mysql.default_user, disregards this boundary in SQL experimental mode, utilizing the client’s name that possesses the server cycle.
  • user password: The user password. mysql.default_password defines the default value. In SQL-protected mode, this setting disregards and uses an empty password.
  • new_link: If you make a subsequent call to mysql_connect() with similar arguments, it doesn’t create a new connection; instead, it returns the connection identifier of the already opened connection. The new_link parameter modifies this behavior and ensures that mysql_connect() always opens a new connection, regardless of whether a previous call used similar arguments. In SQL experimental mode, the system overlooks this boundary.
  • client_flags: The client_flags boundary can be a mix of the accompanying constants: 128 (empower LOAD DATA LOCAL dealing with), MYSQL_CLIENT_SSL, MYSQL_CLIENT_COMPRESS, MYSQL_CLIENT_IGNORE_SPACE, or MYSQL_CLIENT_INTERACTIVE. Peruse the part about MySQL client constants for additional data. In SQL experimental mode, this boundary is disregarded.

Examples of PHP 7 mysql_connect

Now let’s see different examples of PHP 7 MySQL connect for better understanding.

Example #1

Now let’s see an example as follows.

Code:

<?PHP
$servername = "localhost";
$username = "specified username";
$password = "user password";
// Creating connection with MySQL server
$conn = new mysql($servername, $specified username, $user password);
// Connection checking
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connection done successfully";
?>
로그인 후 복사

Output:

PHP 7 mysql_connect 

This is a straightforward example of a PHP 7 mysql connection. After executing the program, we will get a success message, as shown in the following screenshot.

Example #2

Now let’s see another example as follows.

Code:

<?PHP
mysqli_connect("specified localhost", "specified root", "", "   ");
if(mysql_connect_error())
echo "Connection Problem.";
else
echo "Database Connection Done.";
?>
로그인 후 복사

Output:

PHP 7 mysql_connect 

Conclusion

We hope you learn more about the PHP 7 mysql_connect from this article. From the above article, we have taken in the essential idea of the PHP 7 mysql_connect and the representation and example of the PHP 7 mysql_connect. This article taught us how and when to use PHP 7 mysql_connect.

위 내용은 PHP 7 mysql_connect 의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
php
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!