本程序仅供php+mysql爱好者学习测试用,测试过程中,可能会出现错误,请朋友们根据错误提示修改本程序,本程序为安装版,先运行install目录,然后根据提示操作!
关于PHP语法的那些就不说了,我就说一下连接mysql吧!
代码如下 | 复制代码 |
$conn =@mysql_connect("localhost","root","mydown") or die("数据库链接错误"); mysql_select_db("bbs", $conn); mysql_query("set names 'GBK'"); |
第一句就是描述了连接数据库的语句,并且如果失败的提示”数据库连接错误“;前面的三个参数分别代表了 数据库地址localhost,数据库用户名root,连接数据库密码mydown;
第二句就是描述了连接到数据库表bbs,后面的$conn代表哪个数据库。
第三句话就是转换编码格式,显示中文。
连接好了数据库之后,我们来看下 数据库语句怎么在PHP中提交运行!
代码如下 | 复制代码 |
$sql="INSERT INTO message (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; mysql_query($sql); |
上面中的蓝色字体大家应该面熟,意思就是 在数据库中插入信息。第二句是在数据库中运行该语句。想起中类似$_POST[title]的变量,大家应该知道,这是通过网页提交获取的信息
实例
install安装
代码如下 | 复制代码 |
|
check_install.php
代码如下 | 复制代码 |
//获取提交的数据库值 if (!$fp) { if ($fw) { 返回首页 }
|
login.php
代码如下 | 复制代码 |
include("header.php"); if($_GET[out]){
}else{ ?> 退出 if($_GET[sub]=="清空数据库") { $sql="delete from message"; $query=mysql_query($sql); } ?> } ?> |
conn.php数据库连接
代码如下 | 复制代码 |
include("config.php"); $conn =@mysql_connect($server,$server_name,$server_pass) or die("数据库链接错误"); mysql_select_db($server_data, $conn);//此处代表的要打开的数据库名称,"bbs"是我的数据库名,修改成自己的! mysql_query("set names 'GBK'"); //使用GBK中文编码; ?> |
index.php文件
代码如下 | 复制代码 | ||
include("conn.php");
|
add.php增加留方程序
代码如下 | 复制代码 |
include("header.php"); |
test.php数据库结构
代码如下 | 复制代码 |
include("config.php"); |

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
