Idiorm (MySQL) - Raw query - SHOW TABLES LIKE - mysql

I use Idiorm as ORM for MySQL with PHP.
I need to check if a table is created or not.
In SQL
This works in phpMyAdmin
SHOW TABLES LIKE 'ro_globals'
What I tried in Idiorm
ORM::raw_query("SHOW TABLES LIKE 'ro_globals'")->count()
Call to undefined method admin::count()
Is it possible to make this work with Idiorm? If so, how?

The correct anwser is:
ORM::forTable()->rawQuery('SHOW TABLES')->findMany()->count();
or with underscore:
ORM::for_table()->raw_query('SHOW TABLES')->find_many()->count();
Prefixed tables:
ORM::for_table()->raw_query('SHOW TABLES LIKE ' . $prefix . '%')->find_many()->count();

I got the answer in a comment by Saharsh. It's not a Idiorm problem, it could be solved with SQL.
Result
CREATE TABLE IF NOT EXISTS

Related

How to select database with dot in its name with laravel?

i have a project to show database value...
but, the database name has dot in it.
my database name is "t.produk".
How can i select the database in laravel?
i run it and got an error says it invalid like below
EDIT:
and i also did it with just string, came out error too :
Here the picture
First of all - avoid naming database tables like that. You should not use any dots there. It could be t_produk as example.
But table name should be descriptive so go for something like products. Than name your entity as Product.
You get this error here because you can't set variable as (t.produk). You should pass a string as I see here. So do it like this:
protected $table = 't.produk';
EDIT:
I saw the error with a string variable. So now you see why the current table naming you choose is quite not good. DB reads it as follows:
select from database t table produk
If you will name your table like t_produk problem should be no longer here.
My bad, so the tables name can't have dot in it. noted.
Btw y'all thanks for the answers :)

MySQL Queries - Display information created by 'sys'

I'm learning to work with databases and have been learning to write queries based on the tables created.
I'm trying to display information about all the views that were created by the sys user.
I've tried Information_Schema but it returns results that I've created and not the 'sys'.
I'm not sure if I'm attempting it correctly, but I'm getting a result with;
EXEC sp_tables
#table_owner ='sys';
but as it still displays everything and not just 'view' - when I try;
EXEC sp_tables
#table_owner ='sys',
#table_type = 'view';
It returns no data.
Not sure how to work this one out. Tried many things but all were wrong.
I don't know if I got this right but have tried :
SELECT * FROM INFORMATION_SCHEMA.Views where TABLE_schema='sys'

Can i use question mark in MySQL this way

i'm using node.js to build a web. I connect to my database (Mysql) and
get the data then return to the client side.
I know that i can use the literal template to write my sql expression like below
promise(`SELECT table.name FROM table WHERE name = ?`,[parameter])
and i'm would like to know can i write my sql expression like this?
promise(`SELECT table.? FROM table`,[parameter])
I know the result is different, i just want to know it is right or not.
thank you and have a nice day.
No, but you could use string interpolation like:
promise(`SELECT table.name FROM table WHERE name = ${parameter}`)

why ami getting this #1305 - FUNCTION homeshopping.partID does not exist

mysql php admin table query enter image description here
I don't see why it says partID is giving me a problem? it is in the table and i think i have them linked correctly. I Have changed a few things i replaced comma with the and statement which cleared up alot of my errors. But since I've done that it continues to give me #1305 - FUNCTION homeshopping.partID does not exist. I have even looked at the structures an designer to make sure column names an tables are correct.
Don't forget to post your query as text also.
Because it's missing the keywork IN to have a query like this:
SELECT CONCAT(hscust.first,' ', hscust.last AS Customer,hsitems.description,hsitems.price,hsitems.itemCalss
FROM hscust,hsorders,hslineitem,hsitems
WHERE hslineitems.orderId = hsorders.orderId AND hsitems.partID = hslineitem.partNum AND hslineitem.price = hsitems.price AND partID IN ('CB03', 'CZ82');

What is the "Rails Way" of doing a query with an OR clause using ActiveRecord?

I'm using Rails 3 with a MySQL database, and I need to programmatically create a query like this:
select * from table where category_name like '%category_name_1%'
OR category_name like '%category_name_2%'
(...snip...)
OR category_name like '%category_name_n%'
Given the table size and the project scope (500 rows at most, I think), I feel that using something like thinking sphinx would be overkill.
I know I could simply do this by writing the query string directly, but wanted to know if there's an ActiveRecord way to do this. There's no mention of this on the official guide, and I've been googling for a long while now, just to end empty-handed :(
Also, is there a reason (maybe a Rails reason?) to not to include the OR clause?
Thanks!
Assuming you have an array names with category names:
Model.where( names.map{"category_name LIKE ?"}.join(" OR "),
*names.map{|n| "%#{n}%" } )
you should google first, there is already an answer.
Look here and then here
and you'll get something like this:
accounts = Account.arel_table
Account.where(accounts[:name].matches("%#{user_name}%").or(accounts[:name].matches("%#{user_name2}%")))
If you look at the guide, they have examples that can easily be modified to this:
Client.where("orders_count = ? OR locked = ?", params[:orders], false)
Mysql has a regexp function now that can clean things up a bit, assuming there's no regex metachars in your category names:
Table.where "category_name regexp '#{names.join('|')}'"