PHP mysqli如何连接MySQL数据库
在学习1. 开启PHP的API支持
(1)首先修改您的php.ini的配置文件。
查找下面的语句:
;extension=php_mysqli.dll
将其修改为:
extension=php_mysqli.dll
(2)重新启动Apache/IIS,即可。
(3)说明:PHP需要单独的文件来支持这个扩展库,一般在PHP目录下的ext目录里能找到php_mysqli.dll文件(PHP
2.PHP mysqli身份证
mysqli是“MySQL, Improved”的缩写,该扩展仅适用于PHP 5。它能用于MySQL 4.1.1和更高版本。该扩展完全支持MySQL 5.1中采用的鉴定协议,也支持预处理语句和多语句API。此外,该扩展还提供了先进的、面向对象的编程接口。
3. mysqli预定义类
mysqli
表达了 PHP 和 MySQL 数据库之间的连接。
构造函数
mysqli - 构造一个新的PHP mysqli对象
方法
autocommit - 打开或关闭自动提交的数据库选项
change_user - 改变指定的数据库连接的用户
character_set_name - 返回数据库连接的默认字符集
close - 关闭一个之前打开的连接
commit - 提交当前事务
connect - 打开一个到 MySQL 数据库服务器的新连接
debug - 执行排错操作
dump_debug_info - 取得排错信息
get_client_info - 返回客户端版本
get_host_info - 返回连接使用的类型
get_server_info - 返回 MySQL 服务器的版本
get_server_version - 返回 MySQL 服务器的版本
init - 初始化PHP mysqli对象
info - 取得最近执行的查询的信息
kill - 要求服务器停止一个 mysql 线程
multi_query - 执行多个查询
more_results - check if more results exist from currently executed multi-query
next_result - reads next result from currently executed multi-query
options - set options
ping - pings a server connection or reconnects if there is no connection
prepare - prepares a SQL query
query - performs a query
real_connect - attempts to open a connection to MySQL database server
escape_string - escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
rollback - rolls back the current transaction
select_db - selects the default database
set_charset - sets the default client character set
ssl_set - sets ssl parameters
stat - gets the current system status
stmt_init- initializes a statement for use with mysqli_stmt_prepare
store_result - transfers a resultset from last query
thread_safe - returns whether thread safety is given or not
use_result - transfers an unbuffered resultset from last query
属性
affected_rows - gets the number of affected rows in a previous MySQL operation
client_info - returns the MySQL client version as a string
client_version - returns the MySQL client version as an integer
errno - returns the error code for the most recent function call
error - returns the error string for the most recent function call
field_count - returns the number of columns for the most recent query
host_info - returns a string representing the type of connection used
info - retrieves information about the most recently executed query
insert_id - returns the auto generated id used in the last query
protocol_version - returns the version of the MySQL protocol used
server_info - returns a string that represents the server version number
server_version - returns the version number of the server as an integer
sqlstate - returns a string containing the SQLSTATE error code for the last error
thread_id - returns the thread ID for the current connection
warning_count - returns the number of warnings generated during execution of the previous SQL statement
4. 基本语法
<ol class="dp-xml"> <li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li> <li class=""><span> </span></li> <li class="alt"><span> /* Connect to a MySQL server 连接数据库服务器 */ </span></li> <li class=""> <span> $</span><span class="attribute"><font color="#ff0000">link</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">mysqli_connect</font></span><span>( </span> </li> <li class="alt"><span> 'localhost', /* The host to connect to 连接MySQL地址 */ </span></li> <li class=""><span> 'user', /* The user to connect as 连接MySQL用户名 */ </span></li> <li class="alt"><span> 'password', /* The password to use 连接MySQL密码 */ </span></li> <li class=""><span> 'world'); /* The default database to query 连接数据库名称*/ </span></li> <li class="alt"><span> </span></li> <li class=""><span> if (!$link) { </span></li> <li class="alt"><span> printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); </span></li> <li class=""><span> exit; </span></li> <li class="alt"><span> } </span></li> <li class=""><span> </span></li> <li class="alt"><span> /* Send a query to the server 向服务器发送查询请求*/ </span></li> <li class=""> <span> if ($</span><span class="attribute"><font color="#ff0000">result</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">mysqli_query</font></span><span>($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) { </span> </li> <li class="alt"><span> </span></li> <li class=""><span> print("Very large cities are: "); </span></li> <li class="alt"><span> </span></li> <li class=""><span> /* Fetch the results of the query 返回查询的结果 */ </span></li> <li class="alt"> <span> while( $</span><span class="attribute"><font color="#ff0000">row</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">mysqli_fetch_assoc</font></span><span>($result) ){ </span> </li> <li class=""><span> printf("%s (%s) ", $row['Name'], $row['Population']); </span></li> <li class="alt"><span> } </span></li> <li class=""><span> </span></li> <li class="alt"><span> /* Destroy the result set and free the memory used for it 结束查询释放内存 */ </span></li> <li class=""><span> mysqli_free_result($result); </span></li> <li class="alt"><span> } </span></li> <li class=""><span> </span></li> <li class="alt"><span> /* Close the connection 关闭连接*/ </span></li> <li class=""><span> mysqli_close($link); </span></li> <li class="alt"> <span> </span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
以上所描写的解决办法能够帮助我们轻松解决PHP mysqli连接数据库的问题。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

MySQL 8.4(2024년 최신 LTS 릴리스)에 도입된 주요 변경 사항 중 하나는 "MySQL 기본 비밀번호" 플러그인이 더 이상 기본적으로 활성화되지 않는다는 것입니다. 또한 MySQL 9.0에서는 이 플러그인을 완전히 제거합니다. 이 변경 사항은 PHP 및 기타 앱에 영향을 미칩니다.

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

이 튜토리얼은 PHP를 사용하여 XML 문서를 효율적으로 처리하는 방법을 보여줍니다. XML (Extensible Markup Language)은 인간의 가독성과 기계 구문 분석을 위해 설계된 다목적 텍스트 기반 마크 업 언어입니다. 일반적으로 데이터 저장 AN에 사용됩니다

문자열은 문자, 숫자 및 기호를 포함하여 일련의 문자입니다. 이 튜토리얼은 다른 방법을 사용하여 PHP의 주어진 문자열의 모음 수를 계산하는 방법을 배웁니다. 영어의 모음은 A, E, I, O, U이며 대문자 또는 소문자 일 수 있습니다. 모음이란 무엇입니까? 모음은 특정 발음을 나타내는 알파벳 문자입니다. 대문자와 소문자를 포함하여 영어에는 5 개의 모음이 있습니다. a, e, i, o, u 예 1 입력 : String = "Tutorialspoint" 출력 : 6 설명하다 문자열의 "Tutorialspoint"의 모음은 u, o, i, a, o, i입니다. 총 6 개의 위안이 있습니다

숙련된 PHP 개발자라면 이미 그런 일을 해왔다는 느낌을 받을 것입니다. 귀하는 상당한 수의 애플리케이션을 개발하고, 수백만 줄의 코드를 디버깅하고, 여러 스크립트를 수정하여 작업을 수행했습니다.

CMS는 콘텐츠 관리 시스템을 의미합니다. 사용자가 고급 기술 지식 없이도 디지털 콘텐츠를 생성, 관리 및 수정할 수 있는 소프트웨어 애플리케이션 또는 플랫폼입니다. CMS를 사용하면 사용자가 콘텐츠를 쉽게 생성하고 구성할 수 있습니다.

배열은 프로그래밍에서 데이터를 처리하는 데 사용되는 선형 데이터 구조입니다. 때로는 배열을 처리 할 때 기존 배열에 새 요소를 추가해야합니다. 이 기사에서는 각 방법에 대한 코드 예제, 출력 및 시간 및 공간 복잡성 분석을 통해 PHP의 배열 끝에 요소를 추가하는 몇 가지 방법에 대해 논의합니다. 배열에 요소를 추가하는 다양한 방법은 다음과 같습니다. 사각형 브래킷 사용 [] PHP에서 배열 끝에 요소를 추가하는 방법은 사각형 브래킷을 사용하는 것입니다 []. 이 구문은 단일 요소 만 추가하려는 경우에만 작동합니다. 다음은 구문입니다. $ array [] = value; 예
