自己写了一个mysql存储过程,以为php有用于调用存储过程的内建函数,查了一下发现只能用mysql_query(call pro())这样的方式,我认为从本质上也就相当于在mysql命令行里执行语句了,由于我的存储过程含有输入输出参数,直接调用会报一个mysql_error错误:XXXXcan't return a result set in the given context

  
google了一下这个错误发现有人用以下的代码解决了这个问题:
原文地址:http://www.phpweblog.net/GaRY/archive/2008/01/29/2752.html#Post

关键就是两点

1
define('CLIENT_MULTI_RESULTS', 131072);

3 $link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());

下面就可以正常使用了,以下是例子程序。

 1 <?php
 2     define('CLIENT_MULTI_RESULTS', 131072);
 3 
 4     $link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());
 5     mysql_select_db("vs") or die("Could not select database");
 6 ?>
 7 
 8 <?php
 9         $result = mysql_query("call get_news_from_class_id(2)") or die("Query failed:" .mysql_error());
10         while($row = mysql_fetch_array($result, MYSQL_ASSOC))
11         {
12                 $line = '<tr><td><a target = _blank href=\''.$row["url"].'\'>'.$row["title"].'('.$row["page_time"].')'.'</a></td></tr>';
14                 echo $line;
15                 printf("\n");
16 
17         }
18         mysql_free_result($result);
19
?>
20 
21 <?php
22     mysql_close($link);
23 ?>

其中的一个参数CLIENT_MULTI_RESULTS不明白是什么意思,google之,在mysql的官方主页上关于mysql提供的c接口的文档
(http://dev.mysql.com/doc/refman/5.0/en/mysql-real-connect.html)里找到了这个参数
和其他一些参数,我大概翻译了一下描述,如下:

Flag Name Flag
Description
CLIENT_COMPRESS Use compression protocol.(使用压缩协议。)
CLIENT_FOUND_ROWS Return the number of found (matched) rows, not the number of
changed rows.(返回找到(匹配)的行数,而不是改变了的行数。)
CLIENT_IGNORE_SIGPIPE Prevents the client library from installing a SIGPIPE signal handler. This can be used to avoid
conflicts with a handler that the application has already
installed.(阻止客户端库安装一个SIGPIPE信号处理器。这个可以用于当应用程序已经安装该处理器的时候避免与其发生冲突。)
CLIENT_IGNORE_SPACE Allow spaces after function names. Makes all functions names
reserved words.(允许在函数名后使用空格。所有函数名可以预留字。)
CLIENT_INTERACTIVE Allow interactive_timeout seconds
(instead of wait_timeout seconds) of
inactivity before closing the connection. The client's session
wait_timeout variable is set to
the value of the session interactive_timeout
variable.(允许使用关闭连接之前的不活动交互超时的描述,而不是等待超时秒数。客户端的会话等待超时变量变为交互超时变量。)
CLIENT_LOCAL_FILES Enable LOAD DATA LOCAL handling.
CLIENT_MULTI_RESULTS Tell the server that the client can handle multiple result sets
from multiple-statement executions or stored procedures. This flag
is automatically enabled if CLIENT_MULTI_STATEMENTS is enabled. See the note
following this table for more information about this
flag.(通知服务器客户端可以处理由多语句或者存储过程执行生成的多结果集。当打开CLIENT_MULTI_STATEMENTS时,这个标志自动的被打开。可以在本表后查看更多关于该标志位的信息。)
CLIENT_MULTI_STATEMENTS Tell the server that the client may send multiple statements in
a single string (separated by “;”). If this flag is not set,
multiple-statement execution is disabled. See the note following
this table for more information about this flag.(通知服务器客户端可以发送多条语句(由分号分隔)。如果该标志为没有被设置,多条语句执行。)
CLIENT_NO_SCHEMA Don't allow the db_name.tbl_name.col_name syntax.
This is for ODBC. It causes the parser to generate an error if you
use that syntax, which is useful for trapping bugs in some ODBC
programs.(不允许“数据库名.表名.列名”这样的语法。这是对于ODBC的设置。当使用这样的语法时解析器会产生一个错误,这对于一些ODBC的程序限制bug来说是有用的。)
CLIENT_ODBC Unused.(不使用)
CLIENT_SSL Use SSL (encrypted protocol). This option should not be set by
application programs; it is set internally in the client library.
Instead, use mysql_ssl_set() before calling mysql_real_connect().(使用SSL。这个设置不应该被应用程序设置,他应该是在客户端库内部是设置的。可以在调用mysql_real_connect()之前调用mysql_ssl_set()来代替设置。)
CLIENT_REMEMBER_OPTIONS Remember options specified by calls to mysql_options(). Without this option, if
mysql_real_connect() fails, you must repeat
the mysql_options() calls before trying to connect
again. With this option, the mysql_options() calls need not be
repeated.(记住通过调用mysql_options()生成的设置。如果不使用这个设置,当mysql_real_connect失败时,再重新连接之前必须反复调用mysql_options()。当然,如果使用这个设置,就不必反复调用了。)

下面有对于CLIENT_MULTI_STATEMENTS的说明:
If you enable CLIENT_MULTI_STATEMENTS
or CLIENT_MULTI_RESULTS, you should
process the result for every call to mysql_query() or mysql_real_query() by using a loop that calls

mysql_next_result()
to determine whether there are more
results. For an example, see Section 20.9.12, “C API Support for Multiple
Statement Execution”
.
如果打开了 CLIENT_MULTI_STATEMENTS或 CLIENT_MULTI_RESULTS,你必须对每一个mysql_query()或者mysql_real_query()的调用结果通过一个循环来处理,在这个循环中,调用mysql_next_result()来决定(发现)是否有更多的结果,如Section 20.9.12,
“C API Support for Multiple Statement Execution”

以上供需要的朋友参考吧。

关于mysql_connect CLIENT_MULTI_RESULTS的更多相关文章

  1. Warning: mysql_connect(): No such file or directory 解决方案总结(操作系统: Mac)

    说明: 本文主要内容参考: Mac下PHP连接MySQL报错"No such file or directory"的解决办法, 并进行个人补充 1. 运行环境: Mac OS X 10.11.4 (M ...

  2. mysql_connect() php7不支持,php5.5可以,是废弃函数

    天用了PHP7,发现和PHP5变化还挺大的,最大的就是MySQL的连接库变了. PHP5中使用mysql_connect()函数进行连接,但实际上,PHP5.5开始,MySQL就不推荐使用了,属于废弃 ...

  3. 解决 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in

    转载 php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql ext ...

  4. php高版本不再使用mysql_connect()来连接数据库

    想用php生成一个mysql数据字典导出来,用到下面代码会 $mysql_conn = mysql_connect ( "$dbserver", "$dbusername ...

  5. 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future:

    php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql extens ...

  6. undefined function mysql_connect()解决方法

    在配置apache+php+mysql后,打开一个php网页文件正常,但是php网页中连接数据库时,出现以下提示: Fatal error: Call to undefined function my ...

  7. 【转】Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticat

    Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticat 当m ...

  8. mysql_connect和mysql_pconnect区别(转)

    php中mysql_pconnect()的实现方式:其实mysql_pconnect()本身并没有做太多的处理,它唯一做的只是在php运行结束后不主动close掉mysql的连接.mysql_pcon ...

  9. PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法

    这篇文章主要介绍了PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,是在进行PHP数据库程序开发中常会遇 ...

随机推荐

  1. PHP简单爬虫 爬取免费代理ip 一万条

    目标站:http://www.xicidaili.com/ 代码: <?php require 'lib/phpQuery.php'; require 'lib/QueryList.php'; ...

  2. console.dir() 与 console.dirxml() 的使用

    在调试JavaScript程序时,有时需要dump某些对象的详细信息.通过手工编写JavaScript代码可以完成这一工作:针对对象的属性进行循环,将循环到的每一个属性值打印出来:可见,这一过程是比较 ...

  3. aarch64_p2

    perl-Crypt-URandom-0.36-6.fc26.noarch.rpm 2017-02-12 07:17 16K fedora Mirroring Project perl-Crypt-X ...

  4. PHP的数据库连接mysqli遍历示例

    $mysqli = mysqli_init(); $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2);//设置超时时间,以秒为单位的连接超时时间 $m ...

  5. python网络编程-同步IO和异步IO,阻塞IO和非阻塞IO

    同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一下本文的上下文. 本文讨论的背景是Linux环境下的network IO. ...

  6. 洛谷P2024食物链

    传送门啦 这道题的特殊之处在于对于任意一个并查集,只要告诉你某个节点的物种,你就可以知道所有节点对应的物种. 比如一条长为4的链 甲->乙->丙->丁 ,我们知道乙是A物种.那么甲一 ...

  7. C语言基础 - read()函数读取文本字节导致判断失误的问题

    工作了几个月,闲着没事又拿起了经典的C程序设计看了起来,看到字符计数一节时想到用read()去读文本作为字符输入,一切OK,直到行计数时问题出现 了,字符总计数没有问题,可行计算就是进行不了,思考了半 ...

  8. Java 容器的打印

    Java容器类库中的两种主要类型,它们的区别在于容器中每个"槽"保存的元素个数 Clollection容器只能在保存一个元素,此类容器包括: List,它以特定顺序保存一组元素 S ...

  9. Linux学习笔记:mkdir创建文件夹

    文件夹,即目录,在linux中使用mkdir创建. 语法:mkdir dir_name 通过 mkdir 命令可以实现在指定位置创建以 dir_name(指定的文件名)命名的文件夹或目录.要创建文件夹 ...

  10. 2015309南皓芯《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    一.实验内容及步骤 (一)使用JDK编译.运行简单的java程序 命令行下的程序开发 步骤一(新建文件夹):打开windows下的cmd → 输入cd Code命令进入Code目录 → 输入md 20 ...