关于mysql_connect CLIENT_MULTI_RESULTS
生活随笔
收集整理的這篇文章主要介紹了
关于mysql_connect CLIENT_MULTI_RESULTS
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
自己寫了一個mysql存儲過程,以為php有用于調用存儲過程的內建函數,查了一下發現只能用mysql_query(call pro())這樣的方式,我認為從本質上也就相當于在mysql命令行里執行語句了,由于我的存儲過程含有輸入輸出參數,直接調用會報一個mysql_error錯誤:XXXXcan't return a result set in the given context
?
原文地址:http://www.phpweblog.net/GaRY/archive/2008/01/29/2752.html#Post
關鍵就是兩點
1 define('CLIENT_MULTI_RESULTS',?131072);2?
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.(允許使用關閉連接之前的不活動交互超時的描述,而不是等待超時秒數??蛻舳说臅挼却瑫r變量變為交互超時變量。) |
| 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時,這個標志自動的被打開??梢栽诒颈砗蟛榭锤嚓P于該標志位的信息。) |
| 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”
??? 以上供需要的朋友參考吧。
轉載于:https://www.cnblogs.com/jking10/p/4652318.html
總結
以上是生活随笔為你收集整理的关于mysql_connect CLIENT_MULTI_RESULTS的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android开发之在程序右上角添加菜单
- 下一篇: setfacl设置特定目录的权限