MySQL Forums
Forum List  »  PHP

First go at MySQL to MySQLi
Posted by: Boluchamid Laacashadola
Date: July 08, 2013 02:52PM

Hi folks

I'm a bit new and I've sort of hit a brick with what I'm doing now. Looked at W3S, PhP.net etc but I can't quite relate it to what I'm trying to do. Here's some old code.

PHP Code:
function getResult($sql) {
$result = mysql_query($sql, $this->conn);
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysql_error());
}
}
Now, this is my MySqli attempt:


function getResult($sql){;

$result = mysqli_query($this->conn ,"$sql" ); //line93
if ($result) {
return $result;
} else {
die("SQL Retrieve Error: " . mysqli_error($sql));//97
}
}

The error I am getting is the null one.

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\1\func.php on line 93

Warning: mysqli_error() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\1\func.php on line 97
SQL Retrieve Error:

Now, the web page that calls up this function uses the this code. I think it's OK though.



$db1 = new dbmember();
$db1->openDB();
$sql="SELECT * from member";
$result=$db1->getResult($sql);
echo "<table border='1'>";
echo "<tr><th>Member ID</th><th>Name</th><th>Address</th><th>Postcode</th><th>Photo</th></tr>";
while($row = mysqli_fetch_assoc($result))

Any help on what's going on would be fantastic - I have been pouring over this code for hours and it feels like I'm hitting my head against a wall.



Edited 1 time(s). Last edit at 07/08/2013 02:53PM by Boluchamid Laacashadola.

Options: ReplyQuote


Subject
Written By
Posted
First go at MySQL to MySQLi
July 08, 2013 02:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.