<?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. 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()
. 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.