Reputation: 1
I am trying to connect to my local host for a class I am in. I have not been able to resolve these errors I have been having. Can any one help? Here is the code.
class mymysqli {
public $db;
function connectdb ($hostname, $database, $mysqli_login, $mysqli_password){
$db=mysqli_connect ($hostname, $mysqli_login, $mysqli_password) or die ('There is an issue');
mysqli_select_db($database, 'conectdb');
return $db;
}
function selectRows ($query){
$resultSet=mysqli_query($query);
if(mysqli_num_rows($resultSet) > 0){
return $resultSet;
}
else{
return false;
}
}
}
$DBConnect = new mymysqli();
$db=$DBConnect->connectdb("localhost","nwtip","root","");
if($db){
$SQL = "SELECT color FROM colors ORDER BY color";
$rs = $DBConnect -> selectRows($SQL);
if ($rs){
$intcount=0;
while(mysqli_fetch_row($rs)){
echo mysqli_result($rs,$intcount,"color")."<br>";
$intcount++;
}
}
}
These are the errors Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\inclass.php on line 10
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\inclass.php on line 14
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\inclass.php on line 15
Upvotes: 0
Views: 119
Reputation: 129
$db=mysqli_connect ($hostname, $mysqli_login, $mysqli_password) or die
$db is not being set first off due to scope
mysqli_select_db($database, 'conectdb');
should read
mysqli_select_db($db, 'conectdb');
Upvotes: 1