Why am I doing this? Can't do that?
$DB =new DB;
Class db
{function SQL ($sql) {
Global $conn; Database
$query = $conn->query ($sql);
$rs = Mysql_fetch_array ($query);
return $rs;
Mysql_free_result ($query);
}
}
function ListName () {
$id =cut (Intval ($weburl [2]);
$rs = $db->sql ("Select title from ' column ' WHERE id =". $id);
return $rs [0];
}
Error:
Notice:undefined variable:db in
Fatal Error:call to a member function SQL () over a non-object in
14 Line Error Line 14th: $rs = $db->sql ("Select title from ' column ' WHERE id =". $id);
Reply to discussion (solution)
$DB =new db; This sentence should be placed under the Create class
$query = $conn->query ($sql);
Change into
$query =mysql_query ($sql, $conn);
Put $db=new db in function ListName ()
$DB =new DB;
This line goes into the ListName function, or listname the $DB global with global before calling to $db in the function.
Now that you've used the global keyword in a SQL function to globally $conn the variable, you know the scope, and you're going to make that mistake.
$query = $conn->query ($sql);
Change into
$query =mysql_query ($sql, $conn);
Change it as you say:
Class db
{function SQL ($sql) {
Global $conn;
$query = $mysql _query ($sql);
$rs = Mysql_fetch_array ($query);
return $rs;
Mysql_free_result ($query);
}
}
$DB =new DB;
function ListName () {
Global $db;
$id = Ourphp_cut (Intval ($weburl [2]);
$rs = $db->sql ("Select title from ' column ' WHERE id =". $id);
return $rs [0];
}
But it's still not working.
Error: notice:undefined variable:mysql_query
Fatal error:function Name must bes a string in
$DB =new DB;
This line goes into the ListName function, or listname the $DB global with global before calling to $db in the function.
Now that you've used the global keyword in a SQL function to globally $conn the variable, you know the scope, and you're going to make that mistake.
According to the error you have said fatal Error:call to a member function query () on a non-object
I changed query () to mysql_query. Fatal Error:call to a member function mysql_query () on a non-object in
What does that mean?
Thank you for solving the
$query = mysql_query ($sql); Solved the