现在,我正在使用此脚本来读取CSV文件的字符串并显示匹配结果:
function bic_query($blz) {
$cdata = -1;
$fp = fopen(DIR_WS_INCLUDES . 'data/swift.csv', 'r');
while ($data = fgetcsv($fp, 1024, ",")) {
if ($data[0] == $blz){
$cdata = array ('blz' => $data[0],
'bic' => $data[7]);
return $cdata;
}
}
}
...
$bic = $adata['bic'];
我不想从CSV文件中读取,而是想读取数据库中的值,并显示结果$ bic变量。谢谢。
阅读php.net的mysqli。您需要建立与数据库的连接。我建议在构造函数中进行一个称为MySQL的课程,并设置连接变量,例如:
class MySQL {
var $hostname;
var $username;
var $password;
var $database;
var $databaseLink;
var $error;
function __construct($port=3306) {
$this->database = 'your database name';
$this->username = 'username';
$this->password = 'password';
$this->hostname = 'hostname' . ':' . $port;
$this->Connect();
}
public function Connect() {
$this->databaseLink = mysql_connect($this->hostname, $this->username, $this->password);
if(!$this->databaseLink) {
$this->error = 'Could not connect: ' . mysql_error($this->databaseLink);
return false;
} else {
return true;
}
阅读手册将使您剩下的内容,但这将使您对如何使用它有一个好主意