一个带PHP的Sql函数

I'm making a basic function for adding logs on admin pages. (Please ignore the values).

$sql = "INSERT INTO logs(query,userid,time,page) VALUES('$query',$userid,NOW(),'$pagename')");

I'm just attempting to have it in a function like this

function myfunctionforlogs(){
 $sql = "INSERT INTO logs(query,userid,time,page)  VALUES('$query',$userid,NOW(),'$pagename')");
 }

In other pages, I'm hoping to call it as

myfunctionforlogs();

What should I do? And thanks!

Sorry all for the misunderstanding. I have about 10 admin pages and I have a table to record logs. The standard query is what I have posted above. Now, I don't want have that code in every single page, so I have a file named "func.php". I'm hoping I can have that query in a function, so I can just call the function when I want to in other files.

your question is really hard to understand, but maybe you want this?

function myfunctionforlogs($query, $userid, $pagename){
    $sql = "INSERT INTO logs(query,userid,time,page)  VALUES('$query',$userid,NOW(),'$pagename')");
    execute_sql($sql); //<-- another function, that actually runs the sql against the DB
}

now you can call your function anywhere you want to log the script:

myfunctionforlogs('select * from test', 'jimmy', 'index.php');

Btw. CamelCase is a much more readable format for function-names and identifiers in general.