一直试图使用程序php连接到数据库,但我得到错误数组字符串转换


Have been trying to connect to the database using procedural php but i get error array to string conversion

<?php
function connect()
{
$conn = new mysqli('localhost','root','','test' ) or
    die ('There is a problem connecting to     the    db.');
return $conn;
}
function select_Db($conn){
   $stmt = $conn->prepare('SELECT id,UserName,Password FROM users') or
       die('Problem with query.');
   $stmt->execute();
   $stmt->bind_result($id,$UserName,$Password);
   $rows = array();
   while ( $row = $stmt->fetch() ) 
       {
     $item = array(
       "id"=> $id, 
       "UserName"=>$UserName, 
       "Password" =>$Password  
     );  
     $rows[] = $item;
   }
   return $rows;
}

一直在尝试使用程序php连接到数据库,但我得到错误数组到字符串转换。下面是代码和相应的错误。请帮助跟踪代码中的错误。

Notice: Array to string conversion in C:'wamp'www'MYSQL_Project'index.php.php on line 15
Notice: Array to string conversion in C:'wamp'www'MYSQL_Project'index.php.php on line 16
Notice: Array to string conversion in C:'wamp'www'MYSQL_Project'index.php.php on line 17

既然你在做SELECT,试着做常规的query()。没有必要使用预处理语句

使其过于复杂。
$res = $conn->query('SELECT id,UserName,Password FROM users');
$rows = array();
while( $row = $res->fetch_assoc() ) $rows[] = $row;