【发布时间】:2015-04-26 14:35:13
【问题描述】:
我确定这个问题很容易回答,但我不明白。 当我尝试连接一个函数时,它会抛出一个“拒绝用户访问'@'localhost'”错误。看起来数组在数组中不可用,因为错误说我没有输入用户名和密码。
代码是:
$config["mysql_host"] = "localhost";
$config["mysql_user"] = "myusername";
$config["mysql_pass"] = "mypass";
$config["db_name"] = "mydb_name";
$config["event_tname"] = "tablename";
function get_events(){
$mysqli = mysqli_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_pass'], $config["db_name"]); //connect to mysql and select the database
$sql = "SELECT * FROM ".$config["event_tname"]; //a simple query
$result = mysqli_query($mysqli, $sql) or die ("Error, please contact the provider!"/* . mysqli_error()*/); //execute
while($all_events = mysqli_fetch_assoc($result)){ //fetch and just print it
foreach($all_events as $key => $val)
echo($val." | ");
}
mysqli_free_result($result);} //END -- clear $result
events(); //just an example: call the function
我必须在阵列上更改什么?
问候, 弗朗茨
【问题讨论】: