[英]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.