We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How does Phalcon execute the native sql

How does Phalcon execute the native sql statement "LOCK TABLE table_name WRITE"; and "UNLOCK TABLES"? ??



58.3k
edited Dec '16

Hello

You can use pdo to do that here



43.9k

Hi,

I think that phalcon doesn't implement such a feature (after a quick look at https://docs.phalcon.io/en/latest/api/Phalcon_Db_Dialect.html)

You will have to do that with raw sql: https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql

Thanks I tried; Does not work

Thanks I tried; Does not work

Is there has an function to lock table??



43.9k

What did you try exactly ?

Show code please ...

Thanks I tried; Does not work

ThinkPHP

    $table_name='autoid_'.$name;
    $auto=M($table_name);
    mysql_query("LOCK TABLES `".$table_name."` WRITE");
    $result=$auto->find();
    $autoid=$result['id'];
    $sava_id=$autoid+$num;
    $result=$auto->execute("UPDATE `".$table_name."` SET `id`='".$sava_id."'");
    mysql_query("UNLOCK TABLES");


43.9k

Hi,

Ok. So,

mysql_query("LOCK TABLES ".$table_name." WRITE");

doesn't work ? Maybe because it is a native mysql command wich is not formulated using phalcon's way. Are there any error in your webserver log ?

Also, to be sure, you may log your sql statement like this : https://docs.phalcon.io/en/latest/reference/model-events.html#logging-low-level-sql-statements