dongshou2024 2011-03-26 15:33
浏览 27

正常处理mysql_XXXX默认链接标识符参数

mysql extension functions are accepting optional link argument, and if not specified, they use last return value from mysql_connect call. I want the same behaviour in my higher level function(s), but have no idea how to implement it. Below is example of ugliness i DO NOT want to use, absolutely:

function get_mysql_info($linkid = null){
    $linkid ? $strInfo = mysql_info($linkid) : $strInfo = mysql_info();
    // followed by multiple tortures by ereg calls even!

I see two possible ways which might (or might not) work:

  1. passthru some real void value (NULL does not qualify, functions are complaining) to lower level and make mysql function to think there is no link argument and do use last remembered resource
  2. retrieve that last remembered resource and go default way explicitly

Had no success with either variant yet, please advise, and thank you!


Excuse the repeat, this is pseudocode attempt to explain further what i want:

function mysql_wrap ( $optional_link_identifier ) {
  mysql_this( $optional_link_identifier ); // use specified link or default (as described above)
  mysql_that( $mandatory_parameter, $optional_link_identifier ); // use specified link or default 
  // so on
}

... as opposed to branching on presence/absence of the optional argument:

function mysql_wrap ( $optional_link_identifier = NULL ) {
  if ( $optional_link_identifier ) 
    mysql_this( $optional_link_identifier ); // use specified link 
  else mysql_this(); // or default 
  if ( $optional_link_identifier ) 
    mysql_that( $mandatory_parameter, $optional_link_identifier ); // use specified link 
  else mysql_that(); // or default 
  // so on. as you see, generalizing the code in the function actually made things even worse
}

so, i'm seeking the way to handle both cases universally.

  • 写回答

1条回答 默认 最新

  • duanli9930 2011-04-04 16:53
    关注

    the mysql_* functions have had their day.

    Use PDO, and you get a fully OOP inteface that is also largely independent of the type of DB server being used.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?