查看: 665|回复: 5
|
PHP:Function 里不能做Recordset??
[复制链接]
|
|
小弟第一次用PHP在function里做recordset,可是出现了问题,IE说select_database那里有问题。
然后同样的coding抄出来function外面就可以跑了。为舍么呢? |
|
|
|
|
|
|
|
发表于 8-8-2006 09:11 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 9-8-2006 03:42 PM
|
显示全部楼层
原帖由 keat8303 于 8-8-2006 02:52 AM 发表
小弟第一次用PHP在function里做recordset,可是出现了问题,IE说select_database那里有问题。
然后同样的coding抄出来function外面就可以跑了。为舍么呢?
可能function里面调用了非global的variable |
|
|
|
|
|
|
|
楼主 |
发表于 9-8-2006 06:19 PM
|
显示全部楼层
<?php
//require_once('config.php');
$hostname_omes = "localhost";
$database_omes = "omes";
$username_omes = "keat";
$password_omes = "";
$omes = mysql_pconnect($hostname_omes, $username_omes, $password_omes) or trigger_error(mysql_error(),E_USER_ERROR);
function tLookup($field,$tbl,$cond){
mysql_select_db($database_omes, $omes);
$sql = "SELECT ".$field." FROM ".$tbl." where ".$cond;
$select_mp = mysql_query($sql, $omes) or die(mysql_error());
$Rsmp = mysql_fetch_assoc($select_mp);
$totalRows_mp = mysql_num_rows($select_mp);
return $sql;
// return $RsLook[$field];
}
echo tLookup("a","tbl","cond");
?>
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\apachefriends\xampp\htdocs\OMES\include\function.php on line 12
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\apachefriends\xampp\htdocs\OMES\include\function.php on line 14 |
|
|
|
|
|
|
|
发表于 9-8-2006 06:35 PM
|
显示全部楼层
<?php
//require_once('config.php');
function tLookup($field,$tbl,$cond){
//改过的一行字 start
$hostname_omes = "localhost";
$database_omes = "omes";
$username_omes = "keat";
$password_omes = "";
$omes = mysql_pconnect($hostname_omes, $username_omes, $password_omes) or trigger_error(mysql_error(),E_USER_ERROR);
//改过的一行字 end
mysql_select_db($database_omes, $omes);
$sql = "SELECT ".$field." FROM ".$tbl." where ".$cond;
$select_mp = mysql_query($sql, $omes) or die(mysql_error());
$Rsmp = mysql_fetch_assoc($select_mp);
$totalRows_mp = mysql_num_rows($select_mp);
return $sql;
// return $RsLook[$field];
}
echo tLookup("a","tbl","cond");
?>
try again! |
|
|
|
|
|
|
|
楼主 |
发表于 9-8-2006 09:00 PM
|
显示全部楼层
谢了kal兄!! |
|
|
|
|
|
|
| |
本周最热论坛帖子
|