douzhang1955
2013-06-22 20:33
浏览 73
已采纳

从mysql数据库中获取一个“单元格”

I have a site which settings are stored in a mysql database table. For getting one setting, I use something like this:

$q = mysql_query("SELECT setting FROM settings WHERE id=1");
$a = mysql_fetch_array($q);
$setting = $a['setting'];

But, isn't there a faster/better way to dump just one "cell" of a mysql table in a variable?

图片转代码服务由CSDN问答提供 功能建议

我有一个站点,其中的设置存储在mysql数据库表中。 对于获取一个设置,我使用类似的东西 这个:

  $ q = mysql_query(“SELECT setting FROM settings WHERE id = 1”); 
 $ a = mysql_fetch_array($ q); 
 $ setting = $  a ['setting']; 
   
 
 

但是,是不是有更快/更好的方法只在变量中转储mysql表的一个“单元格”?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanchong3075 2013-06-22 20:36
    已采纳

    No, that's pretty much it. Some DB libraries offer a ->getOne()-type method, but internally they don't anything different than what you are. Of course, you SHOULD stop using mysql_*() functions. They're deprecated/obsolete. Consider switching to mysqli or PDO

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题