Database connection problem
Posted: Sat Jul 18, 2009 10:53 am
I have the code below.... it doesnt work except when i mover the db connection inside the function......
can anyone assist?
<?php
class user{
@ $db= new mysqli("localhost","usernae","password", "database");
if (mysqli_connect_errno()){
echo "not connected";
}
function get_name($ssid){
$db= $this->db;
$query="select * from table where id='$ssid'";
$result=$db->query($query);
if(($result->num_rows)==1)
{
$row=$result->fetch_object();
$fname=$row->firstName;
$lname=$row->lastName;
$fullname= ucwords($fname. " ".$lname);
return $fullname;
}
}
}
?>
can anyone assist?
<?php
class user{
@ $db= new mysqli("localhost","usernae","password", "database");
if (mysqli_connect_errno()){
echo "not connected";
}
function get_name($ssid){
$db= $this->db;
$query="select * from table where id='$ssid'";
$result=$db->query($query);
if(($result->num_rows)==1)
{
$row=$result->fetch_object();
$fname=$row->firstName;
$lname=$row->lastName;
$fullname= ucwords($fname. " ".$lname);
return $fullname;
}
}
}
?>