may I know how to create a session-based table using Zend Framework? It is because I am required to develop a shopping cart for my project in college.
Can anyone help me to solve this problem? Thanks a lot.
There is a component in ZF for storing sessions in the database, see: http://framework.zend.com/manual/en/zend.session.savehandler.dbtable.html
once you have that setup you just store your shopping cart data in the session using Zend_Session_Namespace as normal.
You might want to have 'virtual tables', which ideally we use for shopping carts.
Having sessions structured into tables, well, that is kinda mess?
Anyways,
The code should be:
$DBconfig = $this->getAdapter()->getConfig();
$db = Zend_Db::factory('PDO_MYSQL', $DBconfig);
$sql = "CREATE TEMPORARY TABLE virtual_table ("`id` INT(11) NOT NULL AUTO_INCREMENT,
`product` VARCHAR(255), `productQty` INT(5) )";
// Setting values
$sql = "INSERT INTO virtual_table "......
and so on...
Results can be stored in Sessions using Zend_Session_Namespace
Here is a link to a wonderful article, which you might want to refer being a beginner in ZF?
Related
I am getting into Supabase and to practice I am making a suuuper simplified website-builder.
However I am having troubles with the row-level-security policies.
I have three tables:
user → with users' information like first name, last name, etc.
website → all websites
user_website → Contains the information which website belongs to which person (since a website can be owned/editted by multiple users)
user
user_id
...
website
website_id
...
user_website
user_id
website_id
user_role
...
I didn't find any useful resource, because honestly I still lack the knowledge to know how to search properly for what I need.
I only found simple expressions like (uid() = user_id), but since the "permissions" are stored in another table, I don't know how to access that.
I used queries like the following but it didn't work as intended:
SELECT
*
FROM
user_website as uw
JOIN website as w
ON uw.website_id = w.website_id
WHERE
uw.user_id = auth.uid()
Help is much appreciated – thanks!
You could define a policy like that:
CREATE POLICY may_edit ON website
FOR UPDATE TO PUBLIC
USING (EXISTS
(SELECT 1 FROM user_website
WHERE user_website.website_id = website.website_id
AND user_website.user_id = uid()
)
);
Here, uid() is a function that returns your current user ID.
This policy will let everyone modify their own website.
I called a friend for help and he pointed out a section in the Supabase docs about "policies with joins" ... yet it still didn't work for me.
The reason was that the RLS-policy on the table website references the table user-website, which didn't allow users yet to access anything.
Solution
RLS-policy for select on website:
auth.uid() in (
select user_id from user_website
where website_id = website.website_id
)
RLS-policy for select on user-website:
auth.uid() = user_id
I have a list of tables in an Oracle Schema. I use SQL Developer to build my queries. I can click on each table within the schema in SQL Developer and get access to a number of tabs, one of which is 'Details':
Within the 'Details' window, I have a property called 'Comments' which contains a description of what the table is for.
Now, I have quite a few tables and I want to somehow grab the table name and description in that comments property for each table and put it into a spreadsheet. Is there any way to do that in SQL Developer? Maybe a query? Or some built in function that iterates over each table and provides that information? I thought about using python, but I'm not sure I can access the 'Details' of the table.
Every once in a while, I find a solution before i have some of you awesome people answer for me, so i thought I'd post up what I found. This is the query I found that works:
select * from all_tab_comments where owner = 'your_schema_name_here'
This provides a list of all the tables in the schema (owner) I want and provides the comments I was looking for. From there, I can just export to an excel spreadsheet.
I created sqlite table to store values of differnet fields as shown below.
CREATE TABLE places_table (PlaceID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, PlaceName VARCHAR(50), PlaceAddress TEXT, PlaceLatitude REAL, PlaceLongitude REAL);
I can assign some value to PlaceLatitude and PlaceLongitude and display the values in UItable. But when I close and restart the application it displays value of these two fields as 0. Other entries (PlaceAddress, PlaceName) do not have this problem.
Can anyone please help me? Thanks for help in advance.
Are you sure first time values are coming from DB? If so then please provide code you wrote to insert data in DB.
I think you have to check condition if table exit or not .
One possibility of such behavior is that you're doing writing operation in your in-bundle sqlite3 database which is read-only. To solve this, you may need to copy the in-bundle sqlite3 database to the app sandbox when user runs the app for the first time.
If this is your case, please follow this thread: Where would you place your SQLite database file in an iPhone app?
I'm newbie in ZF and have some stupid question:
What's the best solution to calculate rows in the table if I work with inherited object of Zend_Db_Table_Abstract class?
For my first web application I use QuickStart tutorial (link text) so if I want to calculate count of rows in the table in controller the simplest solution will be something like that:
$guestbooks = new Default_Model_GuestBook();
$count = count($guestbooks->fetchAll());
But I don't think that fetchAll() is the best solution just to calculate rows in the table because GuestBook table can be really huge. May be it is possible to use something much more easy and simple?
I found in manual that it is possible to work direct with DB Adapter (like $db->query("SELECT COUNT(*) FROM GuestBook");), but in QuickStart tutorial I haven't got that object in controller and I really don't want to create it only for one simple action.
Will be waiting for suggestions!
Thanks
Your model already contains DB Adapter because it also works with DB. You can get access to DB Adapter using getAdapter() method.
$questbooks->getAdapter()->query("SELECT COUNT(*) FROM GuestBook");
I successfully configured Glassfish to work with JDBCrealm using Basic Auth. But it's not working for Jsp page. My jsp page is simple using j_security_check and j_username and j_password. It throws me to UnAuthorizedAccess page (login error page). It's strange that it's working for basic auth and not for form based. What can be potential problem can anybody tell?
Also the structure of JDBCrealm table requirement is so ugly, i mean why is it so unnormalized? what if i want to change the structure? like
Users(Userid int, Username varchar(50), Userpassword varchar(50))
Roles(Roleid int, Rolename varchar(20))
UsersXRoles(UsersXRolesId int, UserId int, RoleId int)
??How should i configure this now?
Thanks in advance :)
I found a library that can do it: http://flexiblejdbcrealm.wamblee.org/
You can create a normalized database and create a view for Glassfish. We have the same layout that you described in your post and our view looks like this:
CREATE OR REPLACE VIEW v_user_role_relation AS
SELECT u.username, u.password, g.groupname
FROM user_group_rel ugr
JOIN users u ON u.user_id = ugr.user_id
JOIN groups g ON g.group_id = ugr.group_id::numeric;
However your other problem may have many reasons. Check if you defined your Realm in the server config and not only in the default config (that happened to me once).