mysql的mysql 查看functionn能否返回一个TABLE的格式吗

& 返回上一个 MySQL 操作产生的文本错误信息
PHP mysql_error 返回上一个 MySQL 操作产生的文本错误信息
mysql_error
mysql_error &
返回上一个 MySQL 操作产生的文本错误信息
string mysql_error
([ resource $link_identifier
从 MySQL 数据库后端来的错误不再发出警告,要用
mysql_error() 来提取错误文本。注意本函数仅返回最近一次
MySQL 函数的执行(不包括 mysql_error() 和
)的错误文本,因此如果要使用此函数,确保在调用另一个
MySQL 函数之前检查它的值。
Example #1 mysql_error 例子
&?php&&&&mysql_connect("localhost",&"mysql_user",&"mysql_password");&&&&mysql_select_db("nonexistentdb");&&&&echo&mysql_errno()&.&":&"&.&mysql_error().&"
";&&&&mysql_select_db("kossu");&&&&mysql_query("SELECT&*&FROM&nonexistenttable");&&&&echo&mysql_errno()&.&":&"&.&mysql_error()&.&"
以上例子将产生如下输出:
1049: Unknown database 'nonexistentdb'
1146: Table 'kossu.nonexistenttable' doesn't exist
PHP mysql_error note #1
Be aware that if you are using multiple MySQL connections you MUST support the link identifier to the mysql_error() function. Otherwise your error message will be blank.
Just spent a good 30 minutes trying to figure out why i didn't see my SQL errors.
PHP mysql_error note #2
Using a manipulation of josh &&&'s function, I created the following. It's purpose is to use the DB to store errors. It handles both original query, as well as the error log. Included Larry Ullman's escape_data() as well since I use it in q().
function escape_data($data){
&global $dbc;
&if(ini_get('magic_quotes_gpc')){
& $data=stripslashes($data);
&return mysql_real_escape_string(trim($data),$dbc);
function q($page,$query){
$result = mysql_query($query);
&if (mysql_errno()) {
& $error = "MySQL error ".mysql_errno().": ".mysql_error()."
&br&When executing:&br&
& $log = mysql_query("INSERT INTO db_errors (error_page,error_text) VALUES ('$page','".escape_data($error)."')");
$query = "INSERT INTO names (first, last) VALUES ('myfirst', 'mylast'");
$result = q("Sample Page Title",$query);
PHP mysql_error note #3
A friend of mine proposed a great solution.
$old_track = ini_set('track_errors', '1');
&& & && if ($this-&db_handle!=FALSE && $db_selection_status!=FALSE)
&& & & & && {
&& & & & && $this-&connected=1;
&& & & & && ini_set('track_errors', $old_track);
&& & & & && }
&& & && else
&& & & & && {
&& & & & && $this-&connected=-1;
&& & & & && $mysql_warning=$php_errormsg;
&& & & & && ini_set('track_errors', $old_track);
&& & & & && throw new mysql_cns_exception(1, $mysql_warning . " " . mysql_error());
&& & & & && }
PHP mysql_error note #4
"Errors coming back from the MySQL database backend no longer issue warnings." Please note, you have an error/bug here. In fact, MySQL 5.1 with PHP 5.2:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'locallllllhost' (11001)
That's a warning, which is not trapped by mysql_error()!
PHP mysql_error note #5
This is a big one - As of MySQL 4.1 and above, apparently, the way passwords are hashed has changed. PHP 4.x is not compatible with this change, though PHP 5.0 is. I'm still using the 4.x series for various compatibility reasons, so when I set up MySQL 5.0.x on IIS 6.0 running PHP 4.4.4 I was surpised to get this error from mysql_error():
MYSQL: Client does not support authentication protocol consider upgrading MySQL client
According to the MySQL site () the best fix for this is to use the OLD_PASSWORD() function for your mysql DB user. You can reset it by issuing to MySQL:
Set PASSWORD for 'user'@'host' = OLD_PASSWORD('password');
This saved my hide.
PHP mysql_error note #6
When creating large applications it's quite handy to create a custom function for handling queries. Just include this function in every script. And use db_query(in this example) instead of mysql_query.
This example prompts an error in debugmode (variable $b_debugmode ). An e-mail with the error will be sent to the site operator otherwise.
The script writes a log file in directory ( in this case /log ) as well.
The system is vulnerable when database/query information is prompted to visitors. So be sure to hide this information for visitors anytime.
Lennart Poot
$b_debugmode = 1; $system_operator_mail = '';
$system_from_mail = '';
function db_query( $query ){
& global $b_debugmode;
& $result = mysql_query($query);
& if (!$result) {
&&& if($b_debugmode){
&& && $message& = '&b&Invalid query:&/b&&br&' . mysql_error() . '&br&&br&';
&& && $message .= '&b&Whole query:&/b&&br&' . $query . '&br&&br&';
&& && die($message);
&&& raise_error('db_query_error: ' . $message);
& return $result;
& function raise_error( $message ){
&&& global $system_operator_mail, $system_from_mail;
&&& $serror=
&&& "Env:& & && " . $_SERVER['SERVER_NAME'] . "
&&& "timestamp: " . Date('m/d/Y H:i:s') . "
&&& "script:& & " . $_SERVER['PHP_SELF'] . "
&&& "error:& && " . $message ."
&&& $fhandle = fopen( '/logs/errors'.date('Ymd').'.txt', 'a' );
&&& if($fhandle){
&& && fwrite( $fhandle, $serror );
&& && fclose(( $fhandle ));
&&& if(!$b_debugmode)
&& && mail($system_operator_mail, 'error: '.$message, $serror, 'From: ' . $system_from_mail );
PHP mysql_error note #7
My suggested implementation of mysql_error():
$result = mysql_query($query) or die("&b&A fatal MySQL error occured&/b&.
&br /&Query: " . $query . "&br /&
Error: (" . mysql_errno() . ") " . mysql_error());
This will print out something like...
A fatal MySQL error occured.
Query: SELECT * FROM table
Error: (err_no) Bla bla bla, you did everything wrong
It's very useful to see your query in order to detect problems with syntax. Most often, the output message from MySQL doesn't let you see enough of the query in the error message to let you see where your query went bad- it a missing quote, comma, or ( or ) could have occured well before the error was detected. I do -not- recomend using this procedure, however, for queries which execute on your site that are not user-specific as it has the potential to leak sensative data. Recomended use is just for debugging/building a script, and for general user-specific queries which would at the worst, leak the users own information to themself.
Good luck,
PHP mysql_error note #8
If you want to display errors like "Access denied...", when mysql_error() returns "" and mysql_errno() returns 0, use& $php_errormsg. This Warning will be stored there.& You need to have track_errors set to true in your php.ini.
Note. There is a bug in either documentation about error_reporting() or in mysql_error() function cause manual for mysql_error(), says:& "Errors coming back from the MySQL database backend no longer issue warnings." Which is not true.
PHP mysql_error note #9
When dealing with user input, make sure that you use
echo htmlspecialchars (mysql_error ());
instead of
echo mysql_error ();
Otherwise it might be possible to crack into your system by submitting data that causes the SQL query to fail and that also contains javascript commands.
Would it make sense to change the examples in the documentation for mysql_query () and for mysql_error () accordingly?
PHP mysql_error note #10
Following are error codes that may appear when you call MySQL from any host language:
PHP mysql_error note #11
Oops, the code in my previous post only works for queries that don't return data (INSERT, UPDATE, DELETE, etc.), this updated function should work for all types of queries (using $result = myquery($query);):
&&& function myquery ($query) {
&& & && $result = mysql_query($query);
&& & && if (mysql_errno())
&& & & & && echo "MySQL error ".mysql_errno().": ".mysql_error()."
&br&When executing:&br&
&& & && return $
PHP mysql_error note #12
My suggested implementation of mysql_error():
$result = mysql_query($query) or die("&b&A fatal MySQL error occured&/b&.
&br /&Query: " . $query . "&br /&
Error: (" . mysql_errno() . ") " . mysql_error());
This will print out something like...
&b&A fatal MySQL error occured&/b&.
Query: SELECT * FROM table
Error: (err_no) Bla bla bla, you did everything wrong
It's very useful to see your query in order to detect problems with syntax. Most often, the output message from MySQL doesn't let you see enough of the query in the error message to let you see where your query went bad- it a missing quote, comma, or ( or ) could have occured well before the error was detected. I do -not- recomend using this procedure, however, for queries which execute on your site that are not user-specific as it has the potential to leak sensative data. Recomended use is just for debugging/building a script, and for general user-specific queries which would at the worst, leak the users own information to themself.
Good luck,
PHP mysql_error note #13
some error can't handle. Example:
ERROR 1044: Access denied for user: 'ituser@mail.ramon.intranet' to database 'itcom'
This error ocurrs when a intent of a sql insert of no authorized user. The results: mysql_errno = 0 and the mysql_error = "" .
PHPMySQL - 函数2010年 总版技术专家分年内排行榜第二
2009年 总版技术专家分年内排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。查看: 2886|回复: 2
请问如何定义一个function,其返回的是table
论坛徽章:0
找了好久都没有找到如何写这种返回table的函数,那位大哥能帮帮忙?谢谢!!
论坛徽章:8
1.CREATE OR REPLACE PACKAGE ROME AS
TYPE RefCursor IS REF CURSOR;
Function GetCompany(key IN char) return RefC
CREATE OR REPLACE PACKAGE BODY ROME IS
Function GetCompany(key IN char) return RefCursor
v_temp RefC
OPEN v_temp FOR
SELECT * FROM Company WHERE com_ID =
2.(适用于PLSQL类型)
Type shifts_ty is RECORD(
& &&&comp_code& & varchar2(10),
& &&&SHIFT_CODE& & varchar2(10),&&
& &&&sft_flg& && &&&varchar2(10),
& &&&beg_tm& && &&&number,
& &&&end_tm& && &&&number,
& &&&skills& && &&&varchar2(10)) ;
Type shifts is Table of shifts_ty index by binary_
FUNCTION test_proc(test varchar2)
return shifts is
shiftspkg SHIFTS;& &--表变量shiftspkg
cursor q1 is select&&
p_code,shifts.shift_code,shifts.WRK_BEG_TM,shifts.WRK_end_TM,
shifts.skills from str_shifts shifts where comp_code ='TSI';&&--str_shifts是与表变量shiftspkg结构完全相同的真实表
& &&&open q1;
& && && &fetch q1
& && && &exit when q1%
& && && &for iCount in 1.. qty.skills.count
& && && &loop
& && && && & shiftspkg(icount).comp_code:= p_
& && && && & shiftspkg(icount).SHIFT_CODE:= qty.shift_
& && && && & shiftspkg(icount).sft_flg:= 'SLOTS';
& && && && & shiftspkg(icount).beg_tm:= qty.wrk_beg_
& && && && & shiftspkg(icount).end_tm:= qty.wrk_end_
& && && && & shiftspkg(icount).skills:= qty.skills(icount);
& &&&return& &
3.使用于SQL类型
create or replace type myScalarType as object
& & ( comp_code varchar2(10),
& && &shift_code varchar2(10),
& && &sft_flg& && &&&varchar2(10),
& && &beg_tm& && &&&number,
& && &end_tm& && &&&number,
& && &skills& && &&&varchar2(10)
create or replace type myArrayType as table of myScalarType
FUNCTION test_proc(test varchar2) return myArrayType
& && && &l_data&&myArrayType := myArrayType()&&;
& &&&begin
& && &&&for i in 1 .. 5
& && &&&loop
& && && && &l_data.
& && && && &l_data( l_data.count ) := myScalarType( 'cc-'||i,
& && && && && && && && && && && && && && && && && & 'sc-'||i,
& && && && && && && && && && && && && && && && && & 'flg-'||i,
& && && && && && && && && && && && && && && && && & i,
& && && && && && && && && && && && && && && && && & i,
& && && && && && && && && && && && && && && && && & test||i );
& && &&&return l_
& && & from THE ( select cast( pkg_test.test_proc('hello') as myArrayType )
& && && && && && &&&from dual ) a
& && & from table ( cast( my_function() as mytabletype& &) )
& && &order by seq
论坛徽章:0
灰墙感谢楼上!!!!!!!!1
itpub.net All Right Reserved. 北京皓辰网域网络信息技术有限公司版权所有    
 北京市公安局海淀分局网监中心备案编号: 广播电视节目制作经营许可证:编号(京)字第1149号20:23 提问
mysql输错了怎么返回上一行
windows下,按回车后就到下一行了,光标怎么弄都回不了上一行了,怎么回呀
示例如下...
mysql& create table student
按赞数排序
Navicat for MySQL是一套专为MySQL设计的强大数据库管理及开发工具,图形化界面让你更容易操作。
1. 另外,你可以按↑,回到上条命令,此时可以改正。
2.退出MySQL:quit或exit
以下是MySQL常用命令:
显示数据库
创建数据库
选择数据库
drop database name 直接删除数据库,不提醒
显示具体的表结构
select 中加上distinct去除重复字段
mysqladmin drop databasename 删除数据库前,有提示。
显示当前mysql版本和当前日期
select version(),current_
修改mysql中root的密码:
shell&mysql -h localhost -u root -p //登录
mysql& update user set password=password("xueok654123") where user='root';
mysql& flush privileges //刷新数据库
mysql& 打开数据库:
mysql& 显示所有数据库
mysql& 显示数据库mysql中所有的表:先然后
mysql& 显示表mysql数据库中user表的列信息);
创建用户firstdb(密码firstdb)和数据库,并赋予权限于firstdb数据库
mysql& cre
mysql& grant all on firstdb.* to firstdb identified by 'firstdb'
会自动创建用户firstdb
mysql默认的是本地主机是localhost,对应的IP地址就是127.0.0.1,所以你用你的IP地址登录会出错,如果你想用你的IP地址登录就要先进行授权用grant命令。
mysql&grant all on . to root@202.116.39.2 identified by "123456";
说明:grant 与on 之间是各种权限,例如:insert,select,update等
on 之后是数据库名和表名,第一个*表示所有的数据库,第二个*表示所有的表
root可以改成你的用户名,@后可以跟域名或IP地址,identified by 后面的是登录用的密码,可以省略,即缺省密码或者叫空密码。
创建一个可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令something做这个
mysql& grant all privileges on . to user@localhost identified by 'something' with
增加新用户
格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
GRANT ALL PRIVILEGES ON . TO monty@localhost IDENTIFIED BY 'something' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO monty@"%" IDENTIFIED BY 'something' WITH GRANT OPTION;
删除授权:
mysql& revoke all privileges on . from root@"%";
mysql& delete from user where user="root" and host="%";
创建一个用户custom在特定客户端登录,可访问特定数据库fangchandb
mysql &grant select, insert, update, delete, create,drop on fangchandb.* to custom@
identified by ' passwd'
mysql & alter table t1 rename t2;
备份数据库
shell& mysqldump -h host -u root -p dbname &dbname_backup.sql
恢复数据库
shell& mysqladmin -h myhost -u root -p create dbname
shell& mysqldump -h host -u root -p dbname & dbname_backup.sql
如果只想卸出建表指令,则命令如下:
shell& mysqladmin -u root -p -d databasename & a.sql
如果只想卸出插入数据的sql命令,而不需要建表命令,则命令如下:
shell& mysqladmin -u root -p -t databasename & a.sql
那么如果我只想要数据,而不想要什么sql命令时,应该如何操作呢?
mysqldump -T./ phptest driver
其中,只有指定了-T参数才可以卸出纯文本文件,表示卸出数据的目录,./表示当前目录,即与mysqldump同一目录。如果不指定driver表,则将卸出整个数据库的数据。每个表会生成两个文件,一个为.sql文件,包含建表执行。另一个为.txt文件,只包含数据,且没有sql指令。
可将查询存储在一个文件中并告诉mysql从文件中读取查询而不是等待键盘输入。可利用外壳程序键入重定向实用程序来完成这项工作。例如,如果在文件my_file.sql 中存放有查
询,可如下执行这些查询:
例如,如果您想将建表语句提前写在sql.txt中,
mysql & mysql -h myhost -u root -p
Mysql5.0支持的字符集
MySQL中的字符集控制做得比较细,可以分为数据库级,表级, 字段级(这一点和ORACLE不同)。我上次改的字符集是数据库级的,对表sysuser没有影响,所以出现了改了字符集却一样无法插入中文的情况。
Drop TABLE IF EXISTS firstdb.users;
Create TABLE firstdb.users (id int(11) NOT NULL auto_increment,username varchar(40) default NULL,birthday date default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;
编译 MySQL 时,指定了一个默认的字符集,这个字符集是 latin1;
安装 MySQL 时,可以在配置文件 (my.ini) 中指定一个默认的的字符集,如果没指定,这个值继承自编译时指定的;
启动 mysqld 时,可以在命令行参数中指定一个默认的的字符集,如果没指定,这个值继承自配置文件中的;
此时 character_set_server 被设定为这个默认的字符集;
当创建一个新的数据库时,除非明确指定,这个数据库的字符集被缺省设定为    character_set_
当选定了一个数据库时,character_set_database 被设定为这个数据库默认的字符集;
在这个数据库里创建一张表时,表默认的字符集被设定为 character_set_database,也就是这个数据库默认的字符集;
当在表内设置一栏时,除非明确指定,否则此栏缺省的字符集就是表默认的字符集;
这个字符集就是数据库中实际存储数据采用的字符集,mysqldump 出来的内容就是这个字符集下的;Query Browser1.1 对中文输入的支持太差劲了,可以用notebook写好后,再copy过去执行
update firstdb.users set username='以' where id=3;
MYSQL 常用命令
1.导出整个数据库
mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 & 导出的
文件名(数据库默认编码是latin1)
mysqldump -u wcnc -p smgp_apps_wcnc & wcnc.sql
2.导出一个表
mysqldump -u 用户名 -p 数据库名 表名& 导出的文件名
mysqldump -u wcnc -p smgp_apps_wcnc users& wcnc_users.sql
3.导出一个数据库结构
mysqldump -u wcnc -p -d -add-drop-table smgp_apps_wcnc &d:wcnc_db.sql
-d 没有数据 -add-drop-table 在每个create语句之前增加一个drop table
4.导入数据库
A:常用source 命令
进入mysql数据库控制台,
如mysql -u root -p
mysql&use 数据库
然后使用source命令,后面参数为脚本文件(如这里用到的.sql)
mysql&source wcnc_db.sql
B:使用mysqldump命令
mysqldump -u username -p dbname & filename
这个没办法返回的,你可以想好比在使用一台电报机,每输入一行就发出去了,发出去的消息如同说出口的话,不能再收回了。
你可以用基于图形界面的客户端,比如mysql workbench
没法返回上一行,你可以直接在下一行输入,和在同一行输入效果一样的。可以考虑使用图形化工具,就不会有这样的问题,如SQLyog
输入分号“;”, 然后按回车键退出,最后按键盘的向上箭头键,你的create table student dddd 这行sql就回来了。
重新敲,建议先在记事本里写成语句,再在黑框里执行
c结束重新输入
控制板没法返回的,这个简单,不要用Ctrl c结束,直接输入;+ enter结束,然后使用向上向下按键重新选你之前对的就OK辣
为什么不用图形管理界面
这个没办法的,只能结束, 不过结束后,你按方向键上
则会出现 你上次输出的代码。}

我要回帖

更多关于 mysql function 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信