mysql从外面获取数据

时间:2018-01-19 16:56:51

标签: php mysql

我想用这段代码从数据库中获取一些数据

$mysql_hostname = "localhost";
$mysql_user     = "root";
$mysql_password = "";
$mysql_database = "test";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
mysql_select_db($mysql_database, $bd);

$result = mysql_query("SELECT author_id FROM user");
while($data = mysql_fetch_array($result)) {
    $sn=$data['author_id'];
}

$lastresult = mysql_query("SELECT * FROM post WHERE id='".$sn."'");

此代码仅提取一个author_id

$sn=$data['author_id']$lastresult仅适用于一个author_id,并且不会提取所有author_id

如何获取所有author_id的数据?

1 个答案:

答案 0 :(得分:4)

您正在覆盖char * FILE_num ; // // from earlier in the program // FILE_num = (char *) malloc (sizeof (char)) ; FILE_num = "0" ; // // skip several things that work but do not relate (maybe) // int lines = 0 , digit ; // // some code that counts lines in a file // if (lines > 0xfffff) { // if file is too large start new file for (digit = strlen (FILE_num) ; digit >= 0 ; digit --) { if (FILE_num [digit] == 'Z') { // add to proper digit FILE_num [digit] = '0' ; } else if (FILE_num [digit] == '9') { // skip :;<=>?@ FILE_num [digit] = 'A' ; break ; } else { FILE_num [digit] ++ ; // segmentation fault here break ; } } // // Some other code to handle overflow of digits // } 每个循环。

$sn

PS:不推荐使用mysql_ *函数,并且存在安全问题。考虑用mysqli_ *函数或PDO替换。