简体   繁体   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;
}

Have been trying to connect to the database using procedural php but i get error array to string conversion. 一直在尝试使用过程php连接到数据库,但我将错误数组转换为字符串。 Below is the code and respective errors. 下面是代码和相应的错误。 Please help to trace error in the code. 请帮助跟踪代码中的错误。

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

Since you're doing a SELECT try doing a regular query() . 由于您正在执行SELECT尝试执行常规query() There's no need to over complicate this using prepared statements 无需使用准备好的语句将其复杂化

$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.

相关问题 我没有数组,但我在 PHP 中得到“数组到字符串的转换” - I have no arrays but I get "Array to string conversion" in PHP 尝试使用数据库中的值获取下拉菜单,但将数组转换为字符串错误(YII2) - Trying to get dropdown menu with values from database but getting array to string conversion error (YII2) Array to String Conversion Error: 如何解决PHP中的这个错误,我已经提供了代码的控制流程 - Array to String Conversion Error: How to solve this error in PHP, I have provided the control flow of code 尝试使用PHP插入MSSQL时出现“数组到字符串转换”错误 - Getting “Array to string conversion” error when trying to insert into MSSQL using PHP 尝试获取字段值时出现“数组到字符串转换错误” - "Array to string conversion error" when trying to get the values of fields 尝试使用Laravel 5.2从存储过程中获取列时,出现了数组到字符串的转换 - I'm getting an Array to string conversion when trying to get a column from a stored procedure using Laravel 5.2 在php类构造中使用数组将数组转换为字符串会出错 - use array in php class construct get Array to string conversion error PHP字符串到数组的转换错误 - PHP string to array conversion error PHP错误数组到字符串的转换 - PHP Error Array to string conversion PHP错误:数组到字符串的转换 - PHP error : Array to string conversion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM