Calling a saved query from MySQL using PHP

Good evening everyone! There was a small question about the use in the php code of calling stored procedures stored on the MySQL server. Here is an example of a classic query output: PHP code 1 $result=mysqlquery(‘SELECT * FROM tbl1’); Everything works fine and great, but…. For example, I already have such a query on the MySQL server itself, which I saved under the ZAPROSIK bookmark. In order not to constantly write the full text of a SELECT query……. how can I access a stored query on the server?? Option c: PHP code 1 $result=mysqlquery(‘ZAPROSIK’); does not roll.

That is, how to work with this bookmark correctly. I just have complex join requests, there are 25 rows, they are saved under different names on the server. Instead of writing these lines in php code, how can you just refer to the name of this saved MySql query?


Answer 1

$res = mysql_query("call ZAPROSIK()");

Answer 2

Did you mean stored procedures and functions? Or Views?

see Using Stored Routines


Answer 3

In MySQL, neither stored procedures nor functions return the result of execution as a table. You could only save your query as VIEW. At the level of accessing the database, working with VIEWlooks like working with a regular table. That is: SELECT * FROM ZAPROSIK.


Answer 4

Try the following code:

$query = “SELECT * FROM ZAPROSIK”;

$result = mysql_query($query);

I use it myself and everything works fine.