PHP/MySQL : Generate unique id - multi-user

How to generate a unique id after form submission in multiuser environment using PHP and MySQL. I am using WAMP.

since you're using wamp I'm assuming you're using phpmyadmin. Inside phpmyadmin you need to create a database, and your table.
All you have to do after that is add a field called ID, make it the primary key (since its the unique value). Also make sure its an int and check the column field A/I is checked.

Related

Can I alter the code and name user fileds of an user table in SAP Business One

When you create a user table, the Code and Name fields are always created by default and I was wondering if I could eliminate the Name field and leave the Code field but as a primary key and of type int for example without this affecting subsequent version updates.
Or altering this would cause problems of some kind?
Thanks.
That's not possible, if you did it that would terminate support form SAP.

If I want to make a new table for Wordpress, do I prefix it with "wp_"?

I noticed that all of the tables in PHPMyAdmin start with "wp_". I want to make a new table to populate with user uploaded images tied to their posts, so can I just name it anything or is it necessary to name it with "wp_"?
Could you? Yes. Should you? No! It's a good practice to use the common prefix for any custom tables.
The table prefix (wp_ by default) is set in your wp-config.php file. Users have the ability to change this prefix themselves.
You'll want to create the table using the same prefix and then take advantage of the database class in WordPress. For instance if you name your table wp_user_images you could refer to it with $wpdb->prefix . 'user_images' (making sure you have access to the wpdb global first).
Also keep in mind that if you're writing code which you plan to distribute you'll need to create the tables programmatically. Some users may have multiple installations of WordPress in a single database with different prefixes providing separation. If one of those users ran your code they would have multiple sites sharing a single table.

unique client Reference id automatic generation Asp.net | Vb.net

My friends and I have started creating an e-commerce website using asp.net (vb.net). We are newbies and don't know much about it.
Can anybody show me how we can automatically generate unique reference id for each client who is purchasing the product from the website?
You can generate unique id's in database table by providing a column which will have a primary key or unique key assigned to it.and you can set auto increment property of that particular column on so it will increment automatically for each new customer entry.
You can also search the web in the mean time for better approach
There are a lot of ways and methods, but you can use the following command:
Dim user_id As Guid = Guid.NewGuid()
That will generate a unique Id for you.
You can also generate the new id automatically in your database table. Just make sure to create column with data type uniqueidentefier and assign it a default value property newid()

Adding unexisting entities while creating another entity

I'm setting up a blog using Asp.net MVC3 and Entity framework 4. Most of the properties of the blog post already exist in the database, and therefore can easily be linked to the blog post during the creation.
One of the last element I've added are sources, these sources have a direct link to my BlogPost and have to be added during the creation of the BlogPost. My idea was to use the entity property Sources of the BlogPost entity, like:
blogPost.Sources.Add(new Source() { Name = source.Value, Url = source.Key.ToString(), Type = "source" });
Unfortunately I'm not allowed to create and add an Source this way, I'm getting the error: "Cannot insert explicit value for identity column in table 'Source' when IDENTITY_INSERT is set to OFF."
I guess this is cause of the ID column which has is an Identity with Identity increment turned on, but I don't set any ID myself. I tried to make id = null, but since its not a null-able it's not allowed either.
I believe turning this feature off let's me add records with my own ID's, but this is not what I want. The database should create the ID's.
Is there a way to add these kinds of properties during creation?
I solved the problem by adding the Source entity again from the database, apparently the entity framework model was generated before the field was set to Identity Increasing and therefore wanted to insert it's own ID's.

Drupal: update filesystem path in the database

how can I change my Drupal filesystem root in the database ?
I moved Drupal to another path. I'm looking for this value to update in the database.
thanks
<EDIT>if you want to change it in the database (why?), you can do it by changing the value of file_directory_path in the variable table:
UPDATE variable SET file_directory_path = 's:5:"files";';
values in the variable table are stored as serialized php variables. the serialized value in the example above means file_directory_path is a string (s) of length 5 with the value files. you have to adapt this to your specific value.
also note that Drupal variables are cached (in the cache table, under the cid variables). for your change in the database to take effect, you have to clear that cache, like DELETE FROM cache WHERE cid = 'variables';.</EDIT>
if you mean the File system path: it's at Administer > Site configuration > File system, or http://yourdrupalsite.com/index.php?q=admin/settings/file-system.
You could also do the following:
//Get the path of the files folder (ex. sites/default/files)
$files_dir = variable_get('file_directory_path', '');
//To set a new path programmatically
variable_set('file_directory_path', 'sites/new-path/files');
Funny, I just had to do that yesterday.
Since i have phpmyadmin available to me, I used that to export the files table, then do some search/replace routines, then import the table, overwriting the data.
But had I not had phpmyadmin to help, I would have created an SQL query to replace the outdated paths...
Funny, I just moved my drupal to another folder, and it was working. Probably I didn't explain my question very well..

Resources