How do I implement a detach model for SQL queries in the Phalcon framework?

Source: Internet
Author: User
Tags php framework
PHP Framework

For example, I have table A and table B, there is a.php the model class under models/, and no B, now in a a SQL query to table B, how to get the B data without creating the model class of B?


Reply to discussion (solution)

Direct write native mysql_connect () mysql_select_db () mysql_query () recycle result set fetch data

$ar = $obj->fetchall ($sql);
Or
$r = $obj->fetchone ($sql);

In fact, Phalcon classes can be used alone, and not necessarily in the framework of the use of
Like what

$connection = new \phalcon\db\adapter\pdo\mysql (Array (        "host" = "localhost",        "username" and "root",        "Password" and "" ",        " dbname "=" test "),    //print_r (Get_class_methods ($connection));//From a supportive approach, It's just a few extensions on the PDO $connection->query (' Set names GBK '); $t = $connection->fetchall (' select * from ' 123 ', 1);p Rint_r ($t);
Array
(
[0] = = Array
(
[id] = 1
[Name] = Zhang San
[Model] = a8-300
[Station] = A
[Qty] = 200
[Time] = 2013-06-05 08:46:00
)

[1] = = Array
(
[id] = 2
[Name] = John Doe
[Model] = a8-300
[Station] = B
[Qty] = 121
[Time] = 2013-06-05 08:48:00
)

[2] = = Array
(
[id] = 3
[Name] = Harry
[Model] = a1-200
[Station] = C
[Qty] = 45
[Time] = 2013-06-05 07:48:00
)

[3] = = Array
(
[id] = 4
[Name] = Zhang San
[Model] = a8-300
[Station] = A
[Qty] = 420
[Time] = 2013-06-05 10:46:00
)

[4] = = Array
(
[id] = 5
[Name] = Harry
[Model] = a8-300
[Station] = C
[Qty] = 500
[Time] = 2013-06-05 13:46:00
)

)
I'm a weird watch.

$ar = $obj->fetchall ($sql);
Or
$r = $obj->fetchone ($sql);

In fact, Phalcon classes can be used alone, and not necessarily in the framework of the use of
Like what

$connection = new \phalcon\db\adapter\pdo\mysql (Array (        "host" = "localhost",        "username" and "root",        "Password" and "" ",        " dbname "=" test "),    //print_r (Get_class_methods ($connection));//From a supportive approach, It's just a few extensions on the PDO $connection->query (' Set names GBK '); $t = $connection->fetchall (' select * from ' 123 ', 1);p Rint_r ($t);
Array
(
[0] = = Array
(
[id] = 1
[Name] = Zhang San
[Model] = a8-300
[Station] = A
[Qty] = 200
[Time] = 2013-06-05 08:46:00
)

[1] = = Array
(
[id] = 2
[Name] = John Doe
[Model] = a8-300
[Station] = B
[Qty] = 121
[Time] = 2013-06-05 08:48:00
)

[2] = = Array
(
[id] = 3
[Name] = Harry
[Model] = a1-200
[Station] = C
[Qty] = 45
[Time] = 2013-06-05 07:48:00
)

[3] = = Array
(
[id] = 4
[Name] = Zhang San
[Model] = a8-300
[Station] = A
[Qty] = 420
[Time] = 2013-06-05 10:46:00
)

[4] = = Array
(
[id] = 5
[Name] = Harry
[Model] = a8-300
[Station] = C
[Qty] = 500
[Time] = 2013-06-05 13:46:00
)

)
I'm a weird watch.

When the index is dependent on the injection of time has established a database connection, if you use this method then there is another connection is not it? Is there a better way? Only one database connection exists

No, the code I posted just means that Phalcon's classes are available alone.

The model class is inherited from the Phalcon database class.
So he has the same method as the base class.
You can see that with the Get_class_methods function.

No, the code I posted just means that Phalcon's classes are available alone.

The model class is inherited from the Phalcon database class.
So he has the same method as the base class.
You can see that with the Get_class_methods function.

In fact, I also think in the beginning, there is no need to die this way.
Now the special egg hurts is that the database was designed before the field name has the keyword "desc", the result does not use SELECT *. Method query, there is no way to get this field, have you encountered this situation?


No, the code I posted just means that Phalcon's classes are available alone.

The model class is inherited from the Phalcon database class.
So he has the same method as the base class.
You can see that with the Get_class_methods function.

In fact, I also think in the beginning, there is no need to die this way.
Now the special egg hurts is that the database was designed before the field name has the keyword "desc", the result does not use SELECT *. Method query, there is no way to get this field, have you encountered this situation?

Have met .... The name of the field is changed ... Or is it possible to?... by other means. It's been a long time forgetting how to handle it.



No, the code I posted just means that Phalcon's classes are available alone.

The model class is inherited from the Phalcon database class.
So he has the same method as the base class.
You can see that with the Get_class_methods function.

In fact, I also think in the beginning, there is no need to die this way.
Now the special egg hurts is that the database was designed before the field name has the keyword "desc", the result does not use SELECT *. Method query, there is no way to get this field, have you encountered this situation?

Have met .... The name of the field is changed ... Or is it possible to?... by other means. It's been a long time forgetting how to handle it.


If you change the field is not realistic ah ... To change the words of many projects are also to change the code, and the amount of data is too large, changed to lock the table, affecting the normal operation of each application. I thought about it. Select * Forget it, and then filter the field? But it always feels like this will also affect efficiency.




Non-Also, the code I posted just means that Phalcon classes are all available separately

Model classes are inherited from the Phalcon database class
So he has the same base class. Method
You can see it with the Get_class_methods function

In fact, I also think in the beginning, there is no need to die this way.
What is particularly painful now is that the database was previously designed with the keyword "desc" in the field name, and the result does not use SELECT *. Method query, there is no way to get this field, have you encountered this situation?

has encountered .... The name of the field is changed ... Or is it possible to?... by other means. It's been a long time forgetting how to handle it.


If you change the field, it's unrealistic ... To change the words of many projects are also to change the code, and the amount of data is too large, changed to lock the table, affecting the normal operation of each application. I thought about it. Select * Forget it, and then filter the field? But it always feels like this will also affect efficiency.





I don't know if I can help you add an apostrophe, it doesn't seem to be an error.





No, the code I posted just means that Phalcon's classes are available alone.

The model class is inherited from the Phalcon database class.
So he has the same method as the base class.
You can see that with the Get_class_methods function.

In fact, I also think in the beginning, there is no need to die this way.
Now the special egg hurts is that the database was designed before the field name has the keyword "desc", the result does not use SELECT *. Method query, there is no way to get this field, have you encountered this situation?

Have met .... The name of the field is changed ... Or is it possible to?... by other means. It's been a long time forgetting how to handle it.


If you change the field is not realistic ah ... To change the words of many projects are also to change the code, and the amount of data is too large, changed to lock the table, affecting the normal operation of each application. I thought about it. Select * Forget it, and then filter the field? But it always feels like this will also affect efficiency.





I don't know if I can help you add an apostrophe, it doesn't seem to be an error.

0.0 This I know, I am speaking in Phalcon to execute $modelsmanager->executequery ($sql); the query method, where $sql= "select ID, name, ' desc ' from ..."; In general, we normally write the keyword with anti-quote, but use Phalcon he will parse SQL, so write not.

What is it? Isn't that what I wrote?

$t = $connection->fetchall (' select * from ' 123 ', 1);

What is it? Isn't that what I wrote?

$t = $connection->fetchall (' select * from ' 123 ', 1);


Public pdostatement executeprepared (pdostatement $statement, array $placeholders, array $dataTypes);

What's the $datatypes here? Only two parameters were passed in the example.

I don't know what you mean.
It's a long time to keep up with your thoughts.

I don't know what you mean.
It's a long time to keep up with your thoughts.

The amount ... The problem was solved, I didn't say the new question clearly, sorry. That's it. E, found this method when looking at a document

Public pdostatement Prepare (string $sqlStatement)//returns a PDO prepared statement to being executed with ' executeprepared ' $statement = $db->prepare (' SELECT * from robots WHERE name =: Name '); $result = $connection->executeprepared ($statem ENT, Array (' name ' = ' Voltron '));p ublic pdostatement executeprepared (pdostatement $statement, array $placeholders, Array $dataTypes)//executes a prepared statement binding. This function uses an integer indexes starting from zero


But his example here executeprepared only two parameters, but there are three parameters in the definition, array $dataTypes is required number of leaflets, want to know what this $datatypes is

I don't know what you mean.
It's a long time to keep up with your thoughts.
Moderator moderator quickly appeared ~~!

  • Related Article

    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.