php mysql connects to database instance_MySQL
An aside, I changed the my.ini encoding of the data to utf-8 at night, and then the database could not be started. I just changed it back to gbk. If anyone knows, let me know what the problem is.
Because it is a link to the database, there is nothing to explain, so just go to the code.
<?php /* Connect to a MySQL server 连接数据库服务器 */ $link = mysqli_connect( 'localhost', /* The host to connect to 连接MySQL地址 */ 'jian', /* The user to connect as 连接MySQL用户名 */ '123456', /* The password to use 连接MySQL密码 */ 'jian'); /* The default database to query 连接数据库名称*/ if (!$link) { printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); exit; }else echo '数据库连接上了!'; /* Close the connection 关闭连接*/ mysqli_close($link); ?>
The jian here is actually the administrator of one of the libraries named jian. There is no need to write the database administrator, because in actual projects, what we may get is the database account, password, and host address of a library administrator.
Test results:
Original database table:
Operation 1: Query student IDs, classes and scores with scores greater than 60
SELECT id,class,scores FROM jian_scores WHERE scores>60
All codes:
<?php /* Connect to a MySQL server 连接数据库服务器 */ $link = mysqli_connect( 'localhost', /* The host to connect to 连接MySQL地址 */ 'jian', /* The user to connect as 连接MySQL用户名 */ '123456', /* The password to use 连接MySQL密码 */ 'jian'); /* The default database to query 连接数据库名称*/ if (!$link) { printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); exit; }else echo '数据库连接上了!'. "<br/>"; if ($result = mysqli_query($link, 'SELECT id,class,scores FROM jian_scores WHERE scores>60 ')) { echo('id 班级 分数 '). "<br/>"; /* Fetch the results of the query 返回查询的结果 */ while( $row = mysqli_fetch_assoc($result) ){ echo $row['id'], " ", $row['class'], " ", $row['scores'], "<br/>"; // printf("%s (%s) ", $row['id'],$row['class'], $row['scores']); } /* Destroy the result set and free the memory used for it 结束查询释放内存 */ mysqli_free_result($result); } /* Close the connection 关闭连接*/ mysqli_close($link); ?>
Result:
Thanks for reading, I hope it can help everyone, thank you for your support of this site!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

$_COOKIEisaPHPsuperglobalforaccessingcookiessentbythebrowser;cookiesaresetusingsetcookie()beforeoutput,readvia$_COOKIE['name'],updatedbyresendingwithnewvalues,anddeletedbysettinganexpiredtimestamp,withsecuritybestpracticesincludinghttponly,secureflag

PHParrayshandledatacollectionsefficientlyusingindexedorassociativestructures;theyarecreatedwitharray()or[],accessedviakeys,modifiedbyassignment,iteratedwithforeach,andmanipulatedusingfunctionslikecount(),in_array(),array_key_exists(),array_push(),arr

TheObserverdesignpatternenablesautomaticnotificationofdependentobjectswhenasubject'sstatechanges.1)Itdefinesaone-to-manydependencybetweenobjects;2)Thesubjectmaintainsalistofobserversandnotifiesthemviaacommoninterface;3)Observersimplementanupdatemetho

UNIONremovesduplicateswhileUNIONALLkeepsallrowsincludingduplicates;1.UNIONperformsdeduplicationbysortingandcomparingrows,returningonlyuniqueresults,whichmakesitsloweronlargedatasets;2.UNIONALLincludeseveryrowfromeachquerywithoutcheckingforduplicates,

APIversioninginPHPcanbeeffectivelyimplementedusingURL,header,orqueryparameterapproaches,withURLandheaderversioningbeingmostrecommended.1.ForURL-basedversioning,includetheversionintheroute(e.g.,/v1/users)andorganizecontrollersinversioneddirectories,ro

The table can be locked manually using LOCKTABLES. The READ lock allows multiple sessions to read but cannot be written. The WRITE lock provides exclusive read and write permissions for the current session and other sessions cannot read and write. 2. The lock is only for the current connection. Execution of STARTTRANSACTION and other commands will implicitly release the lock. After locking, it can only access the locked table; 3. Only use it in specific scenarios such as MyISAM table maintenance and data backup. InnoDB should give priority to using transaction and row-level locks such as SELECT...FORUPDATE to avoid performance problems; 4. After the operation is completed, UNLOCKTABLES must be explicitly released, otherwise resource blockage may occur.

B-TreeindexesarebestformostPHPapplications,astheysupportequalityandrangequeries,sorting,andareidealforcolumnsusedinWHERE,JOIN,orORDERBYclauses;2.Full-Textindexesshouldbeusedfornaturallanguageorbooleansearchesontextfieldslikearticlesorproductdescripti

To effectively protect phpMyAdmin, multiple layers of security measures must be taken. 1. Restrict access through IP, only trusted IP connections are allowed; 2. Modify the default URL path to a name that is not easy to guess; 3. Use strong passwords and create a dedicated MySQL user with minimized permissions, and it is recommended to enable two-factor authentication; 4. Keep the phpMyAdmin version up to fix known vulnerabilities; 5. Strengthen the web server and PHP configuration, disable dangerous functions and restrict file execution; 6. Force HTTPS to encrypt communication to prevent credential leakage; 7. Disable phpMyAdmin when not in use or increase HTTP basic authentication; 8. Regularly monitor logs and configure fail2ban to defend against brute force cracking; 9. Delete setup and
