I am trying to retrieve data from the database (list of products) but I have a blank page when I execute the code.
<?php
$DB_HOST = "@@@";
$DB_NAME = "@@@";
$DB_PASS = "@@@";
$DB_USER = "@@@";
$db_obj = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if($db_obj->connect_errno > 0) {
die('Connection failed [' . $db_obj->connect_error . ']');
}
if($db_obj->connect_errno > 0){
die('Unable to connect [' . $db_obj->connect_errno . ']');
}
?>
<html>
<head>
<title>List of products</title>
</head>
<body>
<?php
$query="SELECT * FROM product";
$result_obj = $db_obj->query($query);
$row=mysql_fetch_row($result);
echo $row;
?>
</body>
</html>
I am doing it right? where is the problem exactly? is the problem can be from the server side?
new try:
<?php
// session_start();
// require("mysqli.php");
$DB_HOST = "webdev.cs.kent.edu";
$DB_NAME = "ralsuhai";
$DB_PASS = "810646396";
$DB_USER = "ralsuhai";
$db_obj = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if($db_obj->connect_errno > 0) {
die('Connection failed [' . $db_obj->connect_error . ']');
}
if($db_obj->connect_errno > 0){
die('Unable to connect [' . $db_obj->connect_errno . ']');
}
?>
<html>
<head>
<title>List of products</title>
</head>
<body>
<?php
$query="SELECT * FROM product";
$result_obj = $db_obj->query($query);
//first try
//while($row=$result_obj->fetch_row() )
//{
// var_dump($row);
//}
//second try
//$res = array();
//while($row = $result->fetch_array(MYSQLI_ASSOC))
//{
//$res[] = $row;
//}
//print_r($res);
?>
<table><tr><th>Product Id</th><th>Name</th><th>Price</th></tr>
<?php
$result_obj = $db_obj->query($query);
while($row=$result_obj->fetch_row() )
{ ?>
<tr>
<td><?=implode('</td><td>',$row)?></td>
</tr>
<?php
}
?>
</table>
<?php
?>
</body>
</html>
mysql_*
andmysqli_*
functions. – Shankar Damodaran Apr 3 '14 at 4:17mysqli_
supports prepared statements and object-oriented approach, whilemysql_
cannot. – Jan Dvorak Apr 3 '14 at 4:20