php调用mysql存储过程和函数的两种方法
存储过程和函数是MySql5.0刚刚引入的。关于这方面的操作在PHP里面没有直接的支持。但是由于Mysql PHP API的设计,使得我们可以在以前的PHP版本中的mysql php api中支持存储过程和函数的调用。
在php中调用存储过程和函数的主要步骤
1。调用存储过程的方法。
a。如果存储过程有 IN/INOUT参数,声明一个变量,输入参数给存储过程,该变量是一对,
一个php变量(也可以不必,只是没有php变量时,没有办法进行动态输入),一个Mysql变量。
b。如果存储过程有OUT变量,声明一个Mysql变量。
mysql变量的声明比较特殊,必须让mysql服务器知道此变量的存在,其实也就是执行一条mysql语句。
输入 set @mysqlvar=$phpvar ;
c。使用mysql_query()/mysql_db_query()执行mysql 变量声明语句。
Mysql_query("set @mysqlvar【=$pbpvar】");
这样,在mysql服务器里面就有一个变量,@mysqlar。如果时IN参数,那么其值可以有phpar传入。
D。 如果时存储过程。
1。执行 call procedure()语句。
也就是mysql_query("call proceduer([var1]…)");
2. 如果有返回值,执行select @ar,返回执行结果。
Mysql_query("select @var)"
接下来的操作就和php执行一般的mysql语句一样了。可以通过mydql_fetch_row()等函数获得结果。
如果时函数。 直接执行 select function() 就可以了。
php调用mysql存储过程和函数的方法一:
php调用mysql存储过程和函数方法二:此方法需要db_mysqli.dll的支持!
调用带有select语句的存储过程就出现 PROCEDURE p can’t return a result set in the given context的错误。Google了半天,在mysql官网上找到一些说法,db_mysql的模块不支持存储过程调用,解决方法是用db_mysqli。测试了一下,果然可以了。
用法比较简单,没啥好说的,从网上copy一段代码吧:
存储过程和函数是MySql5.0刚刚引入的。关于这方面的操作在PHP里面没有直接的支持。但是由于Mysql PHP API的设计,使得我们可以在以前的PHP版本中的mysql php api中支持存储过程和函数的调用。
在php中调用存储过程和函数的主要步骤
1。调用存储过程的方法。
a。如果存储过程有 IN/INOUT参数,声明一个变量,输入参数给存储过程,该变量是一对,
一个php变量(也可以不必,只是没有php变量时,没有办法进行动态输入),一个Mysql变量。
b。如果存储过程有OUT变量,声明一个Mysql变量。
mysql变量的声明比较特殊,必须让mysql服务器知道此变量的存在,其实也就是执行一条mysql语句。
输入 set @mysqlvar=$phpvar ;
c。使用mysql_query()/mysql_db_query()执行mysql 变量声明语句。
Mysql_query("set @mysqlvar【=$pbpvar】");
这样,在mysql服务器里面就有一个变量,@mysqlar。如果时IN参数,那么其值可以有phpar传入。
D。 如果时存储过程。
1。执行 call procedure()语句。
也就是mysql_query("call proceduer([var1]…)");
2. 如果有返回值,执行select @ar,返回执行结果。
Mysql_query("select @var)"
接下来的操作就和php执行一般的mysql语句一样了。可以通过mydql_fetch_row()等函数获得结果。
如果时函数。 直接执行 select function() 就可以了。
php调用mysql存储过程和函数的方法一:
$host=\"localhost\";
$user=\"root\";
$password=\"11212\";
$db=\"samp_db\";
$dblink=mysql_connect($host,$user,$password)
or die(\"can't connect to mysql\");
mysql_select_db($db,$dblink)
or die(\"can't select samp_db\");
$res=mysql_query(\"set @a=$password\",$dblink);
$res=mysql_query(\"call aa(@a)\",$dblink);
$res=mysql_query(\"select @a\",$dblink);
$row=mysql_fetch_row($res);
echo $row[0];
$user=\"root\";
$password=\"11212\";
$db=\"samp_db\";
$dblink=mysql_connect($host,$user,$password)
or die(\"can't connect to mysql\");
mysql_select_db($db,$dblink)
or die(\"can't select samp_db\");
$res=mysql_query(\"set @a=$password\",$dblink);
$res=mysql_query(\"call aa(@a)\",$dblink);
$res=mysql_query(\"select @a\",$dblink);
$row=mysql_fetch_row($res);
echo $row[0];
php调用mysql存储过程和函数方法二:此方法需要db_mysqli.dll的支持!
调用带有select语句的存储过程就出现 PROCEDURE p can’t return a result set in the given context的错误。Google了半天,在mysql官网上找到一些说法,db_mysql的模块不支持存储过程调用,解决方法是用db_mysqli。测试了一下,果然可以了。
用法比较简单,没啥好说的,从网上copy一段代码吧:
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as */
'root', /* The password to use */
'db_name'); /* The default database to query */
if (!$link) {
printf(\"Can't connect to MySQL Server. Errorcode: %sn\", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, \"call se_proc('crm')\")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. \"--------- SR. \" . $row[1] . \"
\");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as */
'root', /* The password to use */
'db_name'); /* The default database to query */
if (!$link) {
printf(\"Can't connect to MySQL Server. Errorcode: %sn\", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, \"call se_proc('crm')\")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. \"--------- SR. \" . $row[1] . \"
\");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
last_insert_id产生的ID 每次连接后保存在服务器中。这意味着函数向一个给定客户端返回的值是该客户端产生对影响AUTO_INCREMENT列的最新语句第一个 AUTO_INCREMENT值的。这个值不能被其它客户端影响,即使它们产生它们自己的 AUTO_INCREMENT值。这个行为保证了你能够找回自己的 ID 而不用担心其它客户端的活动,而且不需要加锁或处理。
mysql的源代码里面,mysql_insert_id是这么定义的
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
{
return mysql->;last_used_con->;insert_id;
}
MYSQL提供给c++,php等的API一般,有个MYSQL结构体。
结构体里面有insert_id, insert_id的类型 my_ulonglong。 其实就是long long.
每次mysql_query操作在mysql服务器上可以理解为一次“原子”操作, 数据库的写操作常常需要锁表的, 是mysql应用服务器锁表不是我们的应用程序锁表。
附上MYSQL结构体的定义。
mysql的源代码里面,mysql_insert_id是这么定义的
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
{
return mysql->;last_used_con->;insert_id;
}
MYSQL提供给c++,php等的API一般,有个MYSQL结构体。
结构体里面有insert_id, insert_id的类型 my_ulonglong。 其实就是long long.
每次mysql_query操作在mysql服务器上可以理解为一次“原子”操作, 数据库的写操作常常需要锁表的, 是mysql应用服务器锁表不是我们的应用程序锁表。
附上MYSQL结构体的定义。
typedef struct st_mysql
{
NET net; /* Communication parameters */
gptr connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info;
char *db;
struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
my_ulonglong extra_info; /* Used by mysqlshow */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag,server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count;
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
my_bool reconnect; /* set to 1 if automatic reconnect */
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
/*
Set if this is the original connection, not a master or a slave we have
added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
*/
my_bool rpl_pivot;
/*
Pointers to the master, and the next slave connections, points to
itself if lone connection.
*/
struct st_mysql* master, *next_slave;
struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
/* needed for send/read/store/use result to work correctly with replication */
struct st_mysql* last_used_con;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
void *thd;
/*
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
from mysql_stmt_close if close had to cancel result set of this object.
*/
my_bool *unbuffered_fetch_owner;
} MYSQL;
{
NET net; /* Communication parameters */
gptr connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info;
char *db;
struct charset_info_st *charset;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_ulonglong affected_rows;
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
my_ulonglong extra_info; /* Used by mysqlshow */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag,server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count;
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
my_bool reconnect; /* set to 1 if automatic reconnect */
/* session-wide random string */
char scramble[SCRAMBLE_LENGTH+1];
/*
Set if this is the original connection, not a master or a slave we have
added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
*/
my_bool rpl_pivot;
/*
Pointers to the master, and the next slave connections, points to
itself if lone connection.
*/
struct st_mysql* master, *next_slave;
struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
/* needed for send/read/store/use result to work correctly with replication */
struct st_mysql* last_used_con;
LIST *stmts; /* list of all statements */
const struct st_mysql_methods *methods;
void *thd;
/*
Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag
from mysql_stmt_close if close had to cancel result set of this object.
*/
my_bool *unbuffered_fetch_owner;
} MYSQL;
虽然只有8分种的表演时间,但是伦敦奥组委却把典型的伦敦街景和4年后将会出现在那里的奥运风紧紧融合在一起。只要看过《木乃伊归来》你就会发现双层巴士在伦敦人心中的意义。因为它在伦敦
辛勤运行了50年。现场的雾和雨伞散发出历史感与现代感兼具的英伦风情。三名自行车队员不在是奥运健儿,而是公园里的普通骑行者。 乘客,过马路的人展示出平凡而多样的伦敦生活。
红色巴士到站了,伦敦小女孩下车和有中国 加拿大 马来西亚 乌克兰血统的塔姆拥抱。塔姆送给她一个有奥运五环的足球,伦敦在期待2012年“用奥运精神激励每一个人”
接着巴士变出了伦敦塔 巴特西发电站 圣保大罗教堂 ,看到这些你自然就会想到英国的历史 看到发电站你肯定就会想到蒸气机。后来它又变出了新建的温布利大球场和奥林匹克公园。最后变成一个
动感十足的大舞台。火辣的利昂娜 刘易斯和英国超级王牌重金属乐队齐柏林飞艇乐队的吉他手吉米
佩奇演绎《全都是爱》 展现出伦敦的时尚和伦敦街头艺术。和中国艺术有着鲜明的对比。
贝克汉姆是伦敦奥运会的形象大使,他把球传到运动员和所有人身边。是希望将伦敦奥运会的诚挚邀请传递给每一个人。 当然贝克汉姆不光代表着足球,他更代表着体育传承精神。就象中国的姚明一样。虽然足球有贝克汉姆是他们英国的骄傲,但在这里绝对不是向世人显示他们的强项。
辛勤运行了50年。现场的雾和雨伞散发出历史感与现代感兼具的英伦风情。三名自行车队员不在是奥运健儿,而是公园里的普通骑行者。 乘客,过马路的人展示出平凡而多样的伦敦生活。
红色巴士到站了,伦敦小女孩下车和有中国 加拿大 马来西亚 乌克兰血统的塔姆拥抱。塔姆送给她一个有奥运五环的足球,伦敦在期待2012年“用奥运精神激励每一个人”
接着巴士变出了伦敦塔 巴特西发电站 圣保大罗教堂 ,看到这些你自然就会想到英国的历史 看到发电站你肯定就会想到蒸气机。后来它又变出了新建的温布利大球场和奥林匹克公园。最后变成一个
动感十足的大舞台。火辣的利昂娜 刘易斯和英国超级王牌重金属乐队齐柏林飞艇乐队的吉他手吉米
佩奇演绎《全都是爱》 展现出伦敦的时尚和伦敦街头艺术。和中国艺术有着鲜明的对比。
贝克汉姆是伦敦奥运会的形象大使,他把球传到运动员和所有人身边。是希望将伦敦奥运会的诚挚邀请传递给每一个人。 当然贝克汉姆不光代表着足球,他更代表着体育传承精神。就象中国的姚明一样。虽然足球有贝克汉姆是他们英国的骄傲,但在这里绝对不是向世人显示他们的强项。
phpmyadmin 3.0 beta版已经发布了,试用了一下还不错。支持create view, foreign key等
Welcome to the beta release of phpMyAdmin 3.0.0. This version supports various features of MySQL 5.1, the Maria and PBXT storage engines and
SweKey hardware authentication. The 3.0 series requires PHP 5.2+ and MySQL 5.0+.
Welcome to the beta release of phpMyAdmin 3.0.0. This version supports various features of MySQL 5.1, the Maria and PBXT storage engines and
SweKey hardware authentication. The 3.0 series requires PHP 5.2+ and MySQL 5.0+.





