How to call a view mysql from phalcon
I'm doing this in my phalcon controller:
$phql = "select id,description,name,dni from ViewUser where name like '%mark%' ";
$usuario = $this->modelsManager->executeQuery($phql);
Apparently I'm getting an error processing the where, why if yo process this:
$phql = "select id,description,name,dni from ViewUser";
$usuario = $this->modelsManager->executeQuery($phql);
I no longer get error.
For the call of the view, already create my model ViewUser.
I do not know what is wrong when I put the conditions in the WHERE.
Any help is welcome. Thank.
Related
I am using Objection.js ORM of Node.js. I want to use whereIn with raw
Here is what I am trying -
var bookingData = await DoctorBookingsModel
.query()
.select('b.id as booking_id','b.appointment_date')
.from('doctor_bookings as b')
.whereIn(raw("DATE(b.appointment_date) = '"+arrUnavailbleDates+"'"))
.first();
But I am getting following error -
Error: Undefined binding(s) detected when compiling SELECT query: select `b`.`id` as `booking_id`, `b`.`appointment_date` from `doctor_bookings` as `b` where DATE(b.appointment_date) = '2020-10-16,2020-10-17' in ?
Please help me.
Any help would be appreciated,
Thanks.
.whereIn(leftSide, rightSide)
requires 2 arguments. Looks like you were maybe trying to write:
.whereIn(raw("DATE(b.appointment_date)"), arrUnavailbleDates)
a bit like this runkit example https://runkit.com/embed/qm1rwz9dff2h
I need to
1. run a select query on MYSQL DB and fetch the records.
2. Records are processed by python script.
I am unsure about the way I should proceed. Is xcom the way to go here? Also, MYSQLOperator only executes the query, doesn't fetch the records. Is there any inbuilt transfer operator I can use? How can I use a MYSQL hook here?
you may want to use a PythonOperator that uses the hook to get the data,
apply transformation and ship the (now scored) rows back some other place.
Can someone explain how to proceed regarding the same.
Refer - http://markmail.org/message/x6nfeo6zhjfeakfe
def do_work():
mysqlserver = MySqlHook(connection_id)
sql = "SELECT * from table where col > 100 "
row_count = mysqlserver.get_records(sql, schema='testdb')
print row_count[0][0]
callMYSQLHook = PythonOperator(
task_id='fetch_from_testdb',
python_callable=mysqlHook,
dag=dag
)
Is this the correct way to proceed?
Also how do we use xcoms to store the records for the following MySqlOperator?'
t = MySqlOperator(
conn_id='mysql_default',
task_id='basic_mysql',
sql="SELECT count(*) from table1 where id > 10",
dag=dag)
I was really struggling with this for the past 90 minutes, here is a more declarative way to follow for newcomers:
from airflow.hooks.mysql_hook import MySqlHook
def fetch_records():
request = "SELECT * FROM your_table"
mysql_hook = MySqlHook(mysql_conn_id = 'the_connection_name_sourced_from_the_ui', schema = 'specific_db')
connection = mysql_hook.get_conn()
cursor = connection.cursor()
cursor.execute(request)
sources = cursor.fetchall()
print(sources)
...your DAG() as dag: code
task = PythonOperator(
task_id = 'fetch_records',
python_callable = fetch_records
)
This returns to the logs the contents of your DB query.
I hope this is of use to someone else.
Sure, just create a hook or operator and call the get_records() method: https://airflow.apache.org/docs/apache-airflow/stable/_modules/airflow/hooks/dbapi.html
I'm trying to delete records in Yii2 using folowing code:
$query = "DELETE `master_contacts`
FROM `master_contacts`
LEFT JOIN `master_list_contacts`
ON `master_list_contacts`.`master_contact_id` = `master_contacts`.`id`
WHERE `master_contacts`.`deleted` = 1
AND `master_list_contacts`.`id` IS NULL";
Yii::$app->db->createCommand($query);
I have Following database structure.
Query works perfectly in mysql client but I can't get it work in yii (although I didn't get any error).
Could someone tell me please how I supposed do this in yii?
If you use pure SQL you should call execute method:
$query = "DELETE `master_contacts`
FROM `master_contacts`
LEFT JOIN `master_list_contacts`
ON `master_list_contacts`.`master_contact_id` = `master_contacts`.`id`
WHERE `master_contacts`.`deleted` = 1
AND `master_list_contacts`.`id` IS NULL";
Yii::$app->db->createCommand($query)->execute();
Hi I am running my own php/mysql application which has its own users table and is imbedded into a joomla site which has its own users table, when i create a new user in my app it creates an associated record in joomla table so i can manage single sign on. This works fine, however I am now trying to delete the user from the joomla table when I delete from my application, this is code:
$rstmp = CustomQuery("select id as id from zzz_users where email='".$deleted_values["Email"]."'");
$datatmp = db_fetch_array($rstmp);
$id = $rstmp["id"];
//Delete from joomla tables
$sql2 = "DELETE * FROM zzz_user_usergroup_map WHERE user_id='$id'"; CustomQuery($sql2);
$sql3 = "DELETE * FROM zzz_users WHERE email='".$deleted_values["Email"]."'"; CustomQuery($sql3);
But it is returning with the following error:
Fatal error: Cannot use object of type QueryResult as array
Help?
Instead of access to id like $id = $rstmp["id"]; you should access to it like $id = $datatmp["id"]; as on the other way you are trying to access to the query result without using fetch
I'm trying to match md5(ID) to an id.
SELECT *
FROM `user` u
WHERE
MD5(`user_id`) = '66f041e16a60928b05a7e228a89c3799'
this is ID = 58
I tried something like this. I know I'm close I just don't know what I'm missing
$criteria = new Criteria();
$criteria->addAnd('md5('.User::USER_ID.')', $_REQUEST['fs'], Criteria::CUSTOM);
$user = UserPeer::doSelectOne($criteria);
Any ideas?
First of all, directly using Criteria objects is deprecated not recommended. You should use Active Query classes.
Using these classes, you will be able to write stuff like this :
UserQuery::create()
->where('md5(User.Password) = ?', $_REQUEST['fs'], PDO::PARAM_STR)
->findOne();
You'll notice that I use the PhpName both of the table and the column in the query.
EDIT : For raw conditions, the parameter type has to be specified. You'll find more information on this issue.
After lenghty T&E process I managed to get it done like this
$c = new Criteria();
$c->add(UserPeer::USER_ID, "md5(user.user_id) = \"".$_REQUEST['fs']."\"", Criteria::CUSTOM); // risk of SQL injection!!
$saved_search = UserPeer::doSelectOne($c);
For some reason PropelORM though that $_REQUEST['fs'] was name of the table rather than the value. \"" solved the problem.