此处将为大家介绍关于PHP+MYSQL网站开发中遇到的问题汇总(2)_MySQL的详细内容,并且为您解答有关php+mysql网站开发全程实例的相关问题,此外,我们还将为您介绍关于CentOS6.4安
此处将为大家介绍关于PHP+MYSQL 网站开发中遇到的问题汇总(2)_MySQL的详细内容,并且为您解答有关php+mysql网站开发全程实例的相关问题,此外,我们还将为您介绍关于CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)_MySQL、centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?、Java使用JDBC连接任意类型数据库(mysql oracle。。)_MySQL、mac os nginx php mysql mac os mysql 启动 mac os 10.11 mysql mac os x 安装mysq的有用信息。
本文目录一览:- PHP+MYSQL 网站开发中遇到的问题汇总(2)_MySQL(php+mysql网站开发全程实例)
- CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)_MySQL
- centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?
- Java使用JDBC连接任意类型数据库(mysql oracle。。)_MySQL
- mac os nginx php mysql mac os mysql 启动 mac os 10.11 mysql mac os x 安装mysq
PHP+MYSQL 网站开发中遇到的问题汇总(2)_MySQL(php+mysql网站开发全程实例)
5. 采用 header() 函数处理单部件查询
在很多 Web 数据库应用中,一些功能往往让用户点击一个连接后,继续停留在当前页面,这样的工作我叫它“单部件查询”。
下面是一个叫做 calling.php 的脚本:
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
Click here!
当用户点击上面的连接时,就去调用 action.php。下面是 action.php 的源码:
// 数据库功能
// 重定向
header("Location: $HTTP_REFERER");
exit;
?>
这里有两个常见的错误需要提醒一下:
调用 header() 函数后要包含一个 exit 语句让脚本停止,否则后续的脚本可能会在头发送前输出。
header() 函数常见的一个错误是:
Warning: Cannot add header information - headers already sent...
header() 函数只能在 HTML 输出之前被调用,因此你需要检查 php 前面可能存在的空行,空格等等。
6. reload 的问题及其解决
我以前在写 PHP 程序时,经常碰到页面刷新时,数据库多处理一次的情况。
我们来看 addcust.php:
$query = "INSERT INTO customer SET surname = $surname, firstname = $firstname"; $connection = mysql_connect("localhost", "fred", "shhh"); mysql_select_db("winestore", $connection); $result = mysql_query($query, $connection); ?> "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > I''ve inserted the customer for you. ?>
假设我们用下面的连接使用这个程序:
http://www.freelamp.com/addcust.php?surname=Smith&firstname=Fred
如果这个请求只提交一次,OK ,不会有问题,但是如果多次刷新,你就会有多条记录插入。
这个问题可以通过 header() 函数解决:下面是新版本的 addcust.php:
$query = "INSERT INTO customer SET surname = $surname, firstname = $firstname"; $connection = mysql_connect("localhost", "fred", "shhh"); mysql_select_db("winestore", $connection); $result = mysql_query($query, $connection); header("Location: cust_receipt.php"); ?>
这个脚本把浏览器重定向到一个新的页面:cust_receipt.php:
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
I''ve inserted the customer for you.
这样,原来的页面继续刷新也没有副作用了。
7. 巧用锁机制来提高应用性能
如果我们要紧急运行一个报表,那么,我们可以对表加写锁,防治别人读写,来提高对这个表的处理速度。
8. 用 mysql_unbuffered_query() 开发快速的脚本
这个函数能用来替换 mysql_query() 函数,主要的区别就是 mysql_unbuffered_query() 执行完查询后马上返回,不需要等待或者对数据库加锁。
但是返回的行数不能用mysql_num_rows() 函数来检查,因为输出的结果集大小未知。
CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)_MySQL
LNMPCentOSNginx
CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)
原文链接
CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)
原文链接
立即学习“PHP免费学习笔记(深入)”;
centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?
centos7 设置 mysql 自启动的配置文件中
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000 #Restart=on-failure #RestartPreventExitStatus=1 #PrivateTmp=false
这里的
[Service]
User=mysql
Group=mysql,
user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?还是其他呢?
Java使用JDBC连接任意类型数据库(mysql oracle。。)_MySQL
package cn.liz.test;import java.io.InputStream;import java.sql.Connection;import java.sql.Driver;import java.sql.SQLException;import java.util.Properties;import org.junit.Test;public class JBDCtest { /** * 编写一个通用的方法, 在不修改源程序的情况下, 可以获取任何数据库的连接 * 解决方案: 把数据库驱动 Driver 实现类的全类名、url、user、password 放入一个 * 配置文件中, 通过修改配置文件的方式实现和具体的数据库解耦. * @throws Exception */ public Connection getConnection() throws Exception{ String driverClass = null; String jdbcUrl = null; String user = null; String password = null; //读取类路径下的 jdbc.properties 文件 InputStream in = getClass().getClassLoader().getResourceAsStream("jdbc.properties"); Properties properties = new Properties(); properties.load(in); driverClass = properties.getProperty("driver"); jdbcUrl = properties.getProperty("jdbcUrl"); user = properties.getProperty("user"); password = properties.getProperty("password"); //通过反射常见 Driver 对象. Driver driver = (Driver) Class.forName(driverClass).newInstance(); Properties info = new Properties(); info.put("user", user); info.put("password", password); //通过 Driver 的 connect 方法获取数据库连接. Connection connection = driver.connect(jdbcUrl, info); return connection; } @Test public void testGetConnection() throws Exception{ System.out.println(getConnection()); }}<span> </span>
<span>jdbc.properties</span>配置文件:
#driver=oracle.jdbc.driver.OracleDriver#jdbcUrl=jdbc:oracle:thin:@localhost:1521:orcl#user=scott#password=javadriver=com.mysql.jdbc.DriverjdbcUrl=jdbc:mysql://localhost:3306/testuser=rootpassword=
mac os nginx php mysql mac os mysql 启动 mac os 10.11 mysql mac os x 安装mysq
今天的关于PHP+MYSQL 网站开发中遇到的问题汇总(2)_MySQL和php+mysql网站开发全程实例的分享已经结束,谢谢您的关注,如果想了解更多关于CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)_MySQL、centos7 设置 mysql 自启动的配置文件中 [Service] User=mysql Group=mysql,user 和 group 这边的 mysql 是指的什么?centos 的登录用户名?、Java使用JDBC连接任意类型数据库(mysql oracle。。)_MySQL、mac os nginx php mysql mac os mysql 启动 mac os 10.11 mysql mac os x 安装mysq的相关知识,请在本站进行查询。
本文标签: