I'm planning on doing a lot of INSERT DELAYED into MyISAM tables. But the tables might not exist yet. Let's say e.g. a new table will exist for each day.
So instead of detecting absence of table in my client and creating then retrying the insert, it seems like a good case for a stored procedure ("function").
Is this possible, and what would it look like?
Are there any downsides to this approach?
For each ad, I allow users to choose up to 5 tags. Right now, in my database, I have it like...
Posting_id TagID
5 1
5 2
5 3
6 5
6 1
But i was thinking if I should make it like...
Posting_id TagID
5 1 2 3
6 5 1
Then first option is much easier to insert and retrieve data. But if I have 100 posts with 3 tags each, that's 300 rows...so ALOT more rows
The second option requires using explode() impode(), etc but it is much cleaner.
Which option should I do and why? thanks!
Ok, this is probably really simple, but I just can't figure it out. I have a primary key in a table that goes from 1-5,000. I need to manually update that id (for other table update purposes) so that it says 5,000-10,000. Can't I manually update this column? Please help!!! Thank you
I'm not sure how password hashing works (will be implementing it later), but need to create database schema now.
I'm thinking of limiting passwords to 4-20 characters, but as I understand after encrypting hash string will be of different length.
So, how to store these passwords in the database?
Hello, I am looking to retreive a numerical value from the database
function adminLevel()
{
$q = "SELECT userlevel FROM ".TBL_USERS." WHERE id = '$_SESSION[id]'";
return mysql_query($q, $this->connection);
}
This is the SQL.
I then wrote the following php/html:
<?php
$q = $database->adminLevel();
if ($q > 7)
{
?>
<a href="newleague.php">Create a new league</a>
<?
}
?>
The problem I have is that the userlevel returned isn't affecting the if statement. It is always displayed. How do i get it to test the value of userlevel is greater than 7?
Thanks
Hey everyone,
After reading about salts password hashing Id like to implement a simple version for an admin area to a site Im building.
If you have any good links with code that have implemented this idea well, I would appreciate it if you could share.
Thanks,
I have a SQL update statement I am running from inside a PHP program. It is prepared and then executed. When I run it in PHP, it reports a constraint violation. When I run the exact same statement from the command line (which I am getting via dBug()), it works with no errors. This sounds impossible, so I keep looking for differences between the statements. The only thing I can see is that when I execute it with an array of arguments, they all appear to be chars, when some should be integers.
Any suggestions for where to look? I can post the code, but that does not seem like it would be helpful, because the code works.
Hello fellow experts,
I have a huge table and I want simple sorting.
It could be so easy. I could just create an index and do some really fast sorting thanks to that index.
But my client wants to put NULLs to the end, which is complicates the whole situation.
Instead of simple: SORT BY name ASC I have to do SORT BY name IS NULL ASC, name ASC. That would be ok, but it because of that my index is useless, and the sorting is very slow.
I don't know if there's a way to solve this problem, but if there is one, I desperately ask for help. :'(
hi
i have Database with date field.
i see the time like: 1900-01-01 13:38:00.000
how i can see it like: 13:38 ?
(i work on sql server 2008)
thank's in advance
date_default_timezone_set('America/Guayaquil');
$cnn->execute('SET NAMES utf8');
$cnn->execute('SET GLOBAL time_zone = "-5:00"');
Hi, the code above is run everytime someone enters the website im developing. Does someone know what the impact (in performance) of those commands is?
A show create table command shows the following:
'columnA' varchar(6) NOT NULL DEFAULT '';
How do I modify that column so that the not null is removed?
I need it to be:
'columnA' varchar(6) DEFAULT NULL;
I thought the following would work, but it has no effect:
ALTER TABLE tbl_name MODIFY columnA varchar(6) DEFAULT NULL;
Can any professional please specify some real world application, where he / she has used this XPath & XSLT for any logic / view?
It creates a great query among some of the people I've communicated with, and so I myself also wants to know about this.
I wish that this question will create a starting point from where new developers will take home some practical experience.
Any help is greatly appreciated.
I am calling below function with the same batchNumber and it is working without problem 15 times and takes the records fromm database without problem but at 16. time the application freezes when the query.list() row is called. It just loses debug focus and not give any exception. This problem probably is not about the hql because I've seen this problem before and I used criteria instead of hql and I got pass this problem. But for this when I use "group by" in criteria(setrojection....) it doesn't return the result as hibernate model(object) just returns a list. But I need the results as model.
Note: about 15 times it is just for test. This is a web aplication and user may click the button many times that calls this funtion to see the taken records from database.
public List<SiteAddressModel> getSitesByBatch(String batchNumber) {
try{
List<SiteAddressModel> siteList;
MigrationPlanDao migrationPlanDao = ServiceFactory.getO2SiteService().getMigrationPlanDao();
Query query = this.getSession().createQuery("from " + persistentClass.getName() + " where " + "siteType =:" + "type and siteName in " +
"(select distinct exchange from " + migrationPlanDao.getPersistentClass().getName() +
" where migrationBatchNumber =:" + "batchNumber" + ")"
);
query.setString("batchNumber", batchNumber);
query.setString("type", "LLU/ASN");
System.out.println("before query");
siteList = query.list();
System.out.println("after query");
return siteList;
}catch (Exception e) {
e.printStackTrace();
}
Hibernate version 3.2.0.ga
SELECT * FROM `TABLE` WHERE
(`PRIMARY_KEY`= `VALUE1`) OR
(`PRIMARY_KEY`= `VALUE2`) OR
(`PRIMARY_KEY`= `VALUE3`) OR
(`PRIMARY_KEY`= `VALUE4`) OR
(`PRIMARY_KEY`= `VALUE5`) OR ...
This works. But is there a faster way?
is there a way to change the order data from a DB are read ? you know , the default order is that they are read from the first data inserted to the latest so is there a way to change it to latest-first?
I've got quite a few SQL statements like such:
SELECT foo FROM things WHERE user_id IN (1,2,3..n)
Is there a known limit to the number of elements that will safely fit in an IN clause like that?
I have a table of values, with one of the columns being of type SET.
If it currently has the members ('a', 'b', 'c', 'd'), how do I add 'e' to the possible values?
I realize that using a SET type is a little strange, and I'm unclear why one would use it instead of a foreign key to another table with the values of the set, but I didn't design the database in question, and can't change it that much.
Thanks for your help!
I really didn't know how to call the topic, but I will try to explain it here.
So, for example, I have 6 queries in one page. Is it possible, that first five of them would be completed and the last one wouldn't be? Is there any possibilities? If there is, what should I do?
Hope you understood smth. Thanks.
I want to take the id of the most recent item in a database, increment it by one and insert that new id in to another table.
I tried:
$select = mysql_query("SELECT id FROM tableName ORDER BY id DESC");
while ($return = mysql_fetch_assoc($select)) {
$id = $return['id'];
$newId = $id++;
}
mysql_query("INSERT INTO anotherTable (someColumn) VALUES ('$newId')");
But it didn't work. How can this be done?
This is for a homework assignment. I just plain don't understand how to do it.
The instructions for this particular question is:
List the branch name for all branches that have at least one
book that has at least 4 copies on hand.
Where the tables in question are:
Branch:
BranchName | BranchId
Henry Downtown | 1
16 Riverview | 2
Henry On The Hill | 3
Inventory:
BookId | BranchId | OnHand
1 | 1 | 2
2 | 3 | 4
3 | 1 | 8
4 | 3 | 1
5 | 1 | 2
6 | 2 | 3
From what I understand, I can get the number of OnHand per branch name with:
SELECT BranchName, SUM(OnHand)
FROM Branch B, Inventory I
WHERE B.BranchId = I.BranchId
GROUP BY BranchName;
but I don't get how I'd do the comparison between the sum of OnHand per branch and 4.
Any help would be appreciated, guys!
SHOW TABLE STATUS LIKE 'foo' returns Data_length - size of all data, and Index_length - size of all indexes. What's the best way to get per-column and per-index breakdown?