
正文
php接口写入数据库 php写入数据到数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php 写入数据库 例子
?php
// 以 MySQL 为例:
mysql_connect('127.0.0.1', 'root', 'root', 3306); // 连接数据库
mysql_select_db('test'); // 选择数据库
mysql_query('set names utf8'); // 执行SQL
// 插入数据语句
$sql = "INSERT INTO table (username, password) VALUES ('Jack@163.com', '123456')";
$r = mysql_query($sql);
if (mysql_affected_rows()) {
echo '新增成功';
} else {
echo mysql_error();
}
相关问答
Q1: php连接mysql,如何用php代码将数据写入数据库?》??
连接php接口写入数据库:mysql_connect("主机","用户","密码");
mysql_select_db("数据库名");
写入数据:mysql_query("insert
into
表名
(字段1php接口写入数据库,字段2)
values
("数据1","数据2")");
php接口写入数据库你的问题太含糊php接口写入数据库,只能给你这个答复php接口写入数据库,不明白再追问。
Q2: php 接收到之后post数据写入数据库
form表单demo:task.html
fieldset id="setFiled"
legend发布任务/legend
form action="registr.php" method="post" id="steForm"
label任务类型:/labelbr
input type="text" name="type" id="taskType" placeholder="请选择任务类型"/br
label酬nbsp;nbsp;金:/labelbr
input type="number" name="money" id="forMoney" min="1" max="1000"/label元/labelbr
label截止时间:/labelbr
input type="datetime" name="time" id="timeSubmit"/span data-year="" data-month="" data-date="" id="showDate"/spanbr
label详细描述:/labelbr
textarea maxlength="512" name="textAray" id="msgArea"/textareabr
input type="submit" name="subMit" id="forSub" value="点击发布" /
/form
扩展资料
php接收POST数据php接口写入数据库的三种方式
1、$_POST 方式接受数据
$_POST 方式是由通过HTTP的POST方法传递过来的数据组成的数组,是一个自动全局变量。
注:只能接收Content-Type:application/x-www-form-urlencode提交的数据。也就是只能接收表单过来的数据。
2、GLOBLES[‘HTTP_RAW_POST_DATA’]
如果访问原始POST数据不是php能够识别的文档类型php接口写入数据库,比如:text/xml 或者soap等等php接口写入数据库,可以用$GLOBLES[‘HTTP_RAW_POST_DATA’]来接收php接口写入数据库,$HTTP_RAW_POST_DATA变量包含有原始POST数据。此变量仅在碰到未识别的MIME数据时产生。
注:$HTTP_RAW_POST_DATA对于enctype=”multipart/form-data”表单数据不可用,也就是说使用$HTTP_RAW_POST_DATA无法接受网页表单post过来的数据。
3、file_get_contents(“php://input”);
如果访问原始POST数据,更好的方法是使用file_get_content(“php://input”)php接口写入数据库;对于未指定Content-Type的POST数据,可以使用该方法读取POST原始数据,包括二进制流也可以和$HTTP_RAW_POST_DATA比起来。它带来的生存眼里更小,并且不需要任何特殊的php.ini设置。
注:php://input不能用于 enctype=”multipart/form-data”
例如:$postStr = file_get_contents("php://input"); //获取POST数据
关于php接口写入数据库和php写入数据到数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







