簡體   English   中英

一直試圖使用過程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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM