php入门之php操作mysql数据库实例代码
这是一篇简单的php和mysql数据查询数据的简单入门篇,我们讲到了最重要的几个函数详细的介绍了一下,有需要的同学可以看看。
代码如下 | 复制代码 |
//链接数据库 $conn = @mysql_connect("localhost","root","88888888") or die ("链接错误"); /* |
语法
mysql_connect(server,user,pwd,newlink,clientflag)参数 描述
server 可选。规定要连接的服务器。
可以包括端口号,例如 "hostname:port",或者到本地套接字的路径,例如对于 localhost 的 ":/path/to/socket"。
如果 PHP 指令 mysql.default_host 未定义(默认情况),则默认值是 'localhost:3306'。
user 可选。用户名。默认值是服务器进程所有者的用户名。
pwd 可选。密码。默认值是空密码。
*/
代码如下 | 复制代码 |
//解决中文乱码 mysql_query("set names 'GBK'"); //打开数据库 |
mysql_select_db() 函数设置活动的 MySQL 数据库。
如果成功,则该函数返回 true。如果失败,则返回 false。
语法
mysql_select_db(database,connection)参数 描述
database 必需。规定要选择的数据库。
connection 可选。规定 MySQL 连接。如果未指定,则使用上一个连接。
代码如下 | 复制代码 |
//执行sql语句 //循环打印所需参数 |
mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 false。
语法
mysql_fetch_array(data,array_type)参数 描述
data 可选。规定规定要使用的数据指针。该数据指针是 mysql_query() 函数产生的结果。
array_type 可选。规定返回哪种结果。可能的值:
MYSQL_ASSOC - 关联数组
MYSQL_NUM - 数字数组
MYSQL_BOTH - 默认。同时产生关联和数字数组

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.