In the phalcon framework, how does one implement SQL queries without a model? PHP Framework
For example, I have tables A and B and A under models. php is A model class without B. now we need to perform an SQL query on Table B in Table A. How can we get B's data without creating B's model class?
Reply to discussion (solution)
Write the native mysql_connect () mysql_select_db () mysql_query () to retrieve data from the recycle result set.
$ Ar = $ obj-> fetchAll ($ SQL );
Or
$ R = $ obj-> fetchOne ($ SQL );
In fact, all Phalcon classes can be used independently, and do not have to be used in the framework.
For example
$ Connection = new \ Phalcon \ Db \ Adapter \ Pdo \ Mysql (array ("host" => "localhost", "username" => "root ", "password" => "", "dbname" => "test"); // print_r (get_class_methods ($ connection); // You can view the supported methods, only some functions are extended on the PDO $ connection-> query ('set names gbk'); $ t = $ connection-> fetchAll ('select * from '123 '', 1); print_r ($ t );
Array
(
[0] => Array
(
[Id] => 1
[Name] => James
[Model] => A8-300
[Station] =>
[Quantity] = & gt; 200
[Time] => 08:46:00
)
[1] => Array
(
[Id] => 2
[Name] => Li Si
[Model] => A8-300
[Station] => B
[Quantity] = & gt; 121
[Time] => 08:48:00
)
[2] => Array
(
[Id] => 3
[Name] => Wang Wu
[Model] => A1-200
[Station] => C
[Quantity] => 45
[Time] => 07:48:00
)
[3] => Array
(
[Id] => 4
[Name] => James
[Model] => A8-300
[Station] =>
[Quantity] = & gt; 420
[Time] => 10:46:00
)
[4] => Array
(
[Id] => 5
[Name] => Wang Wu
[Model] => A8-300
[Station] => C
[Quantity] = & gt; 500
[Time] => 13:46:00
)
)
My table is weird.
$ Ar = $ obj-> fetchAll ($ SQL );
Or
$ R = $ obj-> fetchOne ($ SQL );
In fact, all Phalcon classes can be used independently, and do not have to be used in the framework.
For example
$ Connection = new \ Phalcon \ Db \ Adapter \ Pdo \ Mysql (array ("host" => "localhost", "username" => "root ", "password" => "", "dbname" => "test"); // print_r (get_class_methods ($ connection); // You can view the supported methods, only some functions are extended on the PDO $ connection-> query ('set names gbk'); $ t = $ connection-> fetchAll ('select * from '123 '', 1); print_r ($ t );
Array
(
[0] => Array
(
[Id] => 1
[Name] => James
[Model] => A8-300
[Station] =>
[Quantity] = & gt; 200
[Time] => 08:46:00
)
[1] => Array
(
[Id] => 2
[Name] => Li Si
[Model] => A8-300
[Station] => B
[Quantity] = & gt; 121
[Time] => 08:48:00
)
[2] => Array
(
[Id] => 3
[Name] => Wang Wu
[Model] => A1-200
[Station] => C
[Quantity] => 45
[Time] => 07:48:00
)
[3] => Array
(
[Id] => 4
[Name] => James
[Model] => A8-300
[Station] =>
[Quantity] = & gt; 420
[Time] => 10:46:00
)
[4] => Array
(
[Id] => 5
[Name] => Wang Wu
[Model] => A8-300
[Station] => C
[Quantity] = & gt; 500
[Time] => 13:46:00
)
)
My table is weird.
A database connection has been established when the index is dependent on injection. if this method is used again, another connection will be created, right? Is there a better way? Only one database connection exists
No, the code I post only indicates that all Phalcon classes can be used independently.
The model class inherits from the Phalcon database class.
So he also has a base class method.
You can use the get_class_methods function.
No, the code I post only indicates that all Phalcon classes can be used independently.
The model class inherits from the Phalcon database class.
So he also has a base class method.
You can use the get_class_methods function.
In fact, I thought like this at the beginning, and there was no need to die.
Currently, the keyword "desc" is included in the field name designed before the database. SELECT * is not used for the result *.. This field cannot be obtained for method queries. Have you ever encountered this situation?
No, the code I post only indicates that all Phalcon classes can be used independently.
The model class inherits from the Phalcon database class.
So he also has a base class method.
You can use the get_class_methods function.
In fact, I thought like this at the beginning, and there was no need to die.
Currently, the keyword "desc" is included in the field name designed before the database. SELECT * is not used for the result *.. This field cannot be obtained for method queries. Have you ever encountered this situation?
I have encountered a change in the field name in my impressions... or can I use other methods ?... I have forgotten the processing method for a long time.
No, the code I post only indicates that all Phalcon classes can be used independently.
The model class inherits from the Phalcon database class.
So he also has a base class method.
You can use the get_class_methods function.
In fact, I thought like this at the beginning, and there was no need to die.
Currently, the keyword "desc" is included in the field name designed before the database. SELECT * is not used for the result *.. This field cannot be obtained for method queries. Have you ever encountered this situation?
I have encountered a change in the field name in my impressions... or can I use other methods ?... I have forgotten the processing method for a long time.
It would be unrealistic to change the field... If you want to modify the code for many projects, and the data volume is too large, it will lock the table and affect the normal operation of each application. I thought about simply selecting * and then filtering out the fields? However, we always feel that this will also affect efficiency ..
No, the code I post only indicates that all Phalcon classes can be used independently.
The model class inherits from the Phalcon database class.
So he also has a base class method.
You can use the get_class_methods function.
In fact, I thought like this at the beginning, and there was no need to die.
Currently, the keyword "desc" is included in the field name designed before the database. SELECT * is not used for the result *.. This field cannot be obtained for method queries. Have you ever encountered this situation?
I have encountered a change in the field name in my impressions... or can I use other methods ?... I have forgotten the processing method for a long time.
It would be unrealistic to change the field... If you want to modify the code for many projects, and the data volume is too large, it will lock the table and affect the normal operation of each application. I thought about simply selecting * and then filtering out the fields? However, we always feel that this will also affect efficiency ..
I don't know if I can help you add an Marker. it seems that no error is reported.
No, the code I post only indicates that all Phalcon classes can be used independently.
The model class inherits from the Phalcon database class.
So he also has a base class method.
You can use the get_class_methods function.
In fact, I thought like this at the beginning, and there was no need to die.
Currently, the keyword "desc" is included in the field name designed before the database. SELECT * is not used for the result *.. This field cannot be obtained for method queries. Have you ever encountered this situation?
I have encountered a change in the field name in my impressions... or can I use other methods ?... I have forgotten the processing method for a long time.
It would be unrealistic to change the field... If you want to modify the code for many projects, and the data volume is too large, it will lock the table and affect the normal operation of each application. I thought about simply selecting * and then filtering out the fields? However, we always feel that this will also affect efficiency ..
I don't know if I can help you add an Marker. it seems that no error is reported.
0.0 I know that I am talking about how to execute $ modelsManager-> executeQuery ($ SQL); in phalcon, where $ SQL = "SELECT id, name, 'desc' FROM .... "; generally, the normal writing method will add backticks to the keyword, but phalcon will parse the SQL statement, which won't work ..
Why? Isn't that what I wrote?
$t = $connection->fetchAll('select * from `123`', 1);
Why? Isn't that what I wrote?
$t = $connection->fetchAll('select * from `123`', 1);
public PDOStatement executePrepared(PDOStatement $statement, array $placeholders, array $dataTypes);
What is $ PES ypes here? The example contains only two parameters.
I don't quite understand what you mean
It takes a long time to keep up with your ideas
I don't quite understand what you mean
It takes a long time to keep up with your ideas
Amount... The previous problem was solved, but I did not clarify the new problem. sorry. Yes. e. This method is found when reading the document.
public PDOStatement prepare (string $sqlStatement)//Returns a PDO prepared statement to be executed with ‘executePrepared’$statement = $db->prepare(’SELECT * FROM robots WHERE name = :name’);$result = $connection->executePrepared($statement, array(’name’ => ’Voltron’));public PDOStatement executePrepared (PDOStatement $statement, array $placeholders, array $dataTypes)//Executes a prepared statement binding. This function uses integer indexes starting from zero
However, the example executePrepared here only contains two parameters, but the definition contains three parameters. array $ dataTypes is the required number of leaflets. What is this $ PES ypes?
I don't quite understand what you mean
It takes a long time to keep up with your ideas
The moderator is coming soon ~~!