php mysql_query,变量为查询[关闭]

I am using PHP/MySQL and am not able to get the query to work.

When I do this it works:

$result = mysql_query("SELECT * FROM site_info;");

However, when I make a variable called query and pass it into the function, the query does not work. Does anyone know why this could be? (I need to do some processing on the string; that's why I need to make it a variable and then pass it into the function)

$query = "SELECT * FROM site_info;";
$result = mysql_query($query);

$result = msyql_query($query); should read $result = mysql_query($query);

What 'processing' are you doing on the string? Can you post this?

Also, as @riwette said, you should be using mysqli_query().

I suggest looking into PDO. There are many benefits over using the mysql functions; it'll do you good to take a look.

To answer your question, this should work fine:

$query = "SELECT * from site_info";
$result = mysql_query($query);

There is a typo in your code:

msyql_query != mysql_query

This is the problem: FROM site_info; ";".

Do not put ";" inside the query unless it part of data you are retrieving.

Also I heard that mysql_* is about to be depreciated so you need to get a hand of PDO or mysqli_* or better yet use a PHP Framework.

$result = mysql_query("SELECT * FROM site_info");