用 PHP 调用 MySQL 存储过程
MySQL 5.0 以上支持存储过程。
PHP 5.0 以上的 mysqli 系列函数可以支持操作 MySQL 的存储过程。
以下是一些简单的存储过程和用 PHP 调用的示例。 一、返回单个数据: 1: <?php
2: header("Content-Type:text/html;charset=utf-8");
3:
4: $host = "localhost";
5: $user = "root";
6: $password = "mypassword";
7: $db = "test_store_proc";
8: $dblink = mysqli_connect($host, $user, $password, $db) or die("can't connect to mysql");
9:
10: $dblink->query('SET NAMES UTF8');
11: if ($result = $dblink->query("CALL sp_test0(@num, @x, 123)"))
12: {
13: $rs = $dblink->query("select @num");
14: $row = $rs->fetch_array();
15: echo $row['@num'], '<br>';
16:
17: $rs = $dblink->query("select @x");
18: $row = $rs->fetch_array();
19: echo $row['@x'];
20:
21: mysqli_free_result($rs);
22: }
23: else
24: echo 'error...';
25: mysqli_close($dblink);
26:
27: /*
28: -- Procedure "sp_test0" DDL
29: CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_test0`(OUT num INT, OUT x VARCHAR(16), IN n INT)
30: BEGIN
31: DECLARE nouse int;
32: DECLARE tmp int;
33:
34: SELECT nId INTO nouse from open_news WHERE nID=39;
35: SELECT count(*) INTO tmp from open_news;
36: SET num = tmp;
37:
38: SET x = 'XXX';
39: END;
40: */
41: ?>
42:
二、返回结果集:
1: <?php
2: header("Content-Type:text/html;charset=utf-8");
3:
4: $host = "localhost";
5: $user = "root";
6: $password = "mypassword";
7: $db = "te
相关文档:
step 1)下载源代码包到本地Linux主机,然后解压缩,进入该目录,进行配置,编译和安装
下载mysql5源码mysql-5.0.18.tar.gz到目录/usr/local
cd /usr/local
tar xzvf mysql-5.0.18.tar.gz
cd mysql-5.0.18
./configure --prefix=/usr/local/mysql
make && make install
make过程花的时间比较长
step 2)配置
......
三年前转语言做了J2ee,今天我又回到的原点。三年前我用PHP的开发网站的方式进入了软件这个行业,没想到现在我又回来了,挣扎着痛苦的回来了。
将来的软件开发和管理我将专注于互联网技术的发展。
牢骚发完了。现在让我来记录一下我对SESSION的浅见吧。
通过ini_set('session.use_trans_sid', 0);设置运行环境中关于SESS ......
MySQL语句优化的原则
1、使用索引来更快地遍历表。
缺省情况下建立的索引是非群集索引,但有时它并不是最佳的。在非群集索引下,数据在物理上随机存放在数据页上。合理的索引设计要建立在对各种查询的分析和预测上。一般来说:
a.有大量重复值、且经常有范围查询( > ,< ......
安装环境:VMware Workstation 5.5.0 build-18463
Linux版本:Red Hat Enterprise Linux AS (2.6.9-42.EL)
软件版本:MySQL5 - mysql-5.0.37.tar.gz
Apache2 - httpd-2.2.4.tar.gz
PHP5 - php-5.2.1.tar.gz
(将以上文件保存至/home/tmp目录)
[MySQL]
# cd /home/tmp (进入压缩包 ......