About PHP instantiation of the image, online and other urgent

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.