php - Call to a member function query() WAMP -
this question has answer here:
- can mix mysql apis in php? 5 answers
here php code:
include ('dbconnect.php'); $sql = "select * products"; $result = $conn->query($sql); if($result -> num_rows >0){ while($row = $result -> fetch_assoc()){ echo "$row[productid]"."$row[productname]"; }else { echo "0 results"; } $conn -> close();
here dbconn.php
code. don't know error is, if in dbconn.php
or on other php page.
<?php $conn = mysql_connect("localhost","root","") or die (mysql_error()); $conn = mysql_select_db("shoppingcart",$conn) or die (mysql_error()); ?>
try this, avoid use of mysql instead of mysqli
include ('dbconnect.php'); $sql = "select * your_table"; $result = mysqli_query($conn, $sql); $count = mysqli_num_rows($result); if($count > 0) { while($row = $result->fetch_assoc()){ echo $row['column1'] . $row['column2'] . "<br/>"; } } $conn -> close();
and connection code
$conn = mysqli_connect("localhost","root", "" ,"your_db"); if(!$conn) { die() . mysqli_error(); } else { //echo "connection successfull"; }
Comments
Post a Comment