search
HomeBackend DevelopmentPHP Tutorialphp mysqli类的演示例子

分享一个php使用mysqli类的例子,并附有mysqli类中的方法说明,很全面的,有需要的朋友参考下吧。

php调用mysqli类的例子,代码如下:

<?
set_time_limit(0);

$mysql_cfg["host"]="localhost"; //主机
$mysql_cfg["port"] = 6033; //端口
$mysql_cfg["user"] = "root"; //用户名
$mysql_cfg["pass"]= "pass11";//密码
$mysql_cfg["db"]='test'; //数据库

$db = new mysqli($mysql_cfg["host"], $mysql_cfg["user"], $mysql_cfg["pass"],$mysql_cfg["db"],$mysql_cfg["port"]);
$db->set_charset("utf8");
$query = "SELECT * from part";
if ($result = $db->query($query)) {
    while ($row = $result->fetch_assoc()) {
        printf ("%s (%s)\n", $row['id'], $row['cn_name']);
    }
    $result->close();
}
$db->close();

//mysqli类的实例
?>

mysqli类中的方法,说明:

mysqli_affected_rows -返回一个MySQL操作受影响的行数 mysqli_autocommit -开启或关闭 autocommit 数据库修改 mysqli_bind_param -别名mysqli_stmt_bind_param ( ) mysqli_bind_result -别名mysqli_stmt_bind_result ( ) mysqli_change_user -更改指定数据库连接的用户 mysqli_character_set_name -返回数据库连接的默认字符集 mysqli_client_encoding -别名mysqli_character_set_name ( ) mysqli_close -关闭当前打开数据库连接 mysqli_commit -当前事物 mysqli_connect_errno -返回最后一次操作的错误代码 mysqli_connect_error -返回最后一次操作的错误字符串描述 mysqli_connect -打开一个新的连接到MySQL服务器 mysqli_data_seek -在当前记录结果集中任意移动行指针 mysqli_debug -调试 mysqli_disable_reads_from_master -禁用读取主对像 mysqli_disable_rpl_parse -禁用RPL解析 mysqli_dump_debug_info -转储调试信息的日志 mysqli_embedded_connect -打开一个连接到嵌入式MySQL服务器 mysqli_enable_reads_from_master -启用内容由主 mysqli_enable_rpl_parse -启用RPL解析 mysqli_errno -返回错误代码最近函数调用 mysqli_error -返回一个字符串描述过去的错误 mysqli_escape_string -别名mysqli_real_escape_string ( ) mysqli_execute -别名mysqli_stmt_execute ( ) mysqli_fetch_array -从结果集中取得一行作为关联,数字数组,或两者兼施 mysqli_fetch_assoc -从结果集中取得一行作为关联数组 mysqli_fetch_field_direct -获取元数据的一个单一的领域 mysqli_fetch_field -返回明年领域中的结果集 mysqli_fetch_fields -返回一个数组对象代表领域的结果集 mysqli_fetch_lengths -返回长度列的当前行的结果集 mysqli_fetch_object -返回当前行的结果集作为一个对象 mysqli_fetch_row -取得结果集中取得一行作为枚举数组 mysqli_fetch -别名mysqli_stmt_fetch ( ) mysqli_field_count -返回的列数最近查询 mysqli_field_seek -设为结果指针到指定的外地抵消 mysqli_field_tell -获取当前外地抵消的结果指针 mysqli_free_result -释放内存与结果 mysqli_get_client_info -返回MySQL客户端版本作为一个字符串 mysqli_get_client_version -取得MySQL客户端信息 mysqli_get_host_info -返回一个字符串代表的连接类型使用 mysqli_get_metadata -别名mysqli_stmt_result_metadata ( ) mysqli_get_proto_info -返回版本的MySQL使用协议 mysqli_get_server_info -返回版本的MySQL服务器 mysqli_get_server_version -返回版本的MySQL服务器作为一个整数 mysqli_info -检索信息,最近执行的查询 mysqli_init -初始化MySQLi并返回一个资源使用mysqli_real_connect ( ) mysqli_insert_id -返回自动生成的编号使用最后查询 mysqli_kill -要求服务器要杀死一个MySQL线程 mysqli_master_query -强制执行查询总在主/从设置 mysqli_more_results -检查是否有任何更多的查询结果来自一个多查询 mysqli_multi_query -执行查询数据库 mysqli_next_result -准备明年的结果multi_query mysqli_num_fields -获取的若干领域中的结果 mysqli_num_rows -获取的行数的结果 mysqli_options -设置选项 mysqli_param_count -别名mysqli_stmt_param_count ( ) mysqli_ping -的Ping一个服务器连接,或尝试重新连接,如果已下降 mysqli_prepare -准备一个SQL语句的执行 mysqli_query -执行查询数据库 mysqli_real_connect -打开一个连接到MySQL服务器 mysqli_real_escape_string -转义特殊字符的字符串,用于SQL语句,并考虑到当前的字符集的连接 mysqli_real_query -执行一个SQL查询 mysqli_report -启用或禁用内部报告功能 mysqli_rollback -回滚当前事务 mysqli_rpl_parse_enabled -检查是否启用RPL解析 mysqli_rpl_probe - RPL探针 mysqli_rpl_query_type -返回RPL查询类型 mysqli_select_db -选择的默认数据库数据库查询 mysqli_send_long_data -别名mysqli_stmt_send_long_data ( ) mysqli_send_query -发送查询并返回 mysqli_server_end -关机嵌入式服务器 mysqli_server_init -初始化嵌入式服务器 mysqli_set_charset -集的默认客户端字符集 mysqli_set_opt -别名mysqli_options ( ) mysqli_sqlstate -返回SQLSTATE错误从一个MySQL操作 mysqli_ssl_set -用于建立安全连接使用SSL mysqli_stat -获取当前的系统状态 mysqli_stmt_affected_rows -返回总数列改变,删除或插入的最后执行的声明 mysqli_stmt_bind_param -绑定变量一份声明作为参数 mysqli_stmt_bind_result -绑定变量的一份声明中存储的结果 mysqli_stmt_close -关闭一份声明 mysqli_stmt_data_seek -寻找一个任意行声明的结果集 mysqli_stmt_errno -返回错误代码的最新声明呼吁 mysqli_stmt_error -返回一个字符串描述最后声明错误 mysqli_stmt_execute -执行一个准备查询 mysqli_stmt_fetch -获取结果一份准备好的声明中纳入约束变量 mysqli_stmt_free_result -免储存记忆的结果给予处理的声明 mysqli_stmt_init -初始化了言,并返回一个对象,用于mysqli_stmt_prepare mysqli_stmt_num_rows -返回的行数报表结果集 mysqli_stmt_param_count -返回一些参数给定的声明 mysqli_stmt_prepare -准备一个SQL语句的执行 mysqli_stmt_reset -重置一份声明 mysqli_stmt_result_metadata -返回结果集元数据的一份书面声明 mysqli_stmt_send_long_data -发送数据块 mysqli_stmt_sqlstate -返回SQLSTATE错误行动从以往的声明 mysqli_stmt_store_result -转让的结果集由一份声明 mysqli_store_result -转让的结果集的最后查询 mysqli_thread_id -返回线程ID为当前连接 mysqli_thread_safe -返回是否线程安全考虑或不 mysqli_use_result -开创检索结果集 mysqli_warning_count -返回一些警告过去查询提供链接


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools