mysql

SQL - How to make a conditional INSERT

Using only MySQL, I'm seeing if it's possible run an insert statement ONLY if the table is new. I successfully created a user variable to see if the table exists. The problem is that you can't use "WHERE" along with an insert statement. Any ideas on how to get this working? // See if the "country" table exists -- saving the result to a ...

mysql transaction with accounting application

Hello, I have a table like the following: transaction_id user_id other_user_id trans_type amount This table is used to maintain the account transactions for a finance type app. Its double entry accounting so a transfer from User A to B would insert two rows into the table looking like. 1, A, B, Sent, -100 1, B, A, Received, 100 T...

MySQL - A difficult INSERT...SELECT on the same table [MySQL 5.051]

I am trying to insert a new row into my table which holds the same data as the one I am trying to select from the same table but with a different user_id and without a fixed value for auto_id since that is an auto_increment field, and setting ti to NOW(). Below is my mockup query where '1' is the new user_id. I have been trying many vari...

MySQL, PHP - Forms Help.

Greetings, I have the following code <? include("conn.php"); $sn=$_GET["sn"]; $sql="select * from kpi where no='$sn'"; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $sn=$row['id']; $no=$row['no']; ...

multiple keyword search script needs some expert input

I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like some of the commenters mentioned, the script only ends up returning results based on the last word in the search terms. So I have also tried to implement one of the suggestions from ...

PHP MYSQL - Explode help

Greetings, I have data stored on mysql with delimiter "," in 1 table. I have rows and column stored on database too. Now i have to output the data using rows and column number stored on database to draw the table. Rows and column number are user input, so it may varies. Let say, there is number 3 on column and 3 on rows. I need to ...

mysql import trouble using XAMP

originally i was using easyPHP (windows) then i switch to mac and used MAMP. i archive my db every once in a while and right before i reformatted. The export was made by going into the root of phpMyAdmin and using the export function. Now i am trying to import the data i get this error "#1044 - Access denied for user 'root'@'localhost' t...

Can I compare MySQL enums?

I have an enumeration: ENUM( 'alpha', 'beta', 'gamma', 'delta', 'omega' ) If I sort my table by this column I get them in the correct order defined above. However, I can't find a way to select a subset of these, e.g. everything before delta. Using WHERE status < 'delta' only returns alpha and beta, not gamma. It seems MySQL uses a stri...

What is the best way to insert into and update a single row table in MySQL?

I have a MySQL table that will only have one row. What should my statement be for the first time I insert to this row, and for subsequent updates? I tried an insert where the primary key equals 1, but this doesn't account for the first time around when no row exists yet. Thanks! ...

SQL query to get greatest distinct date - kind of...

I have two tables: articles and articletags articles: id, author, date_time, article_text articletags: id, tag (article.id == articletags.id in a many-to-many relationship) I am after the last time that something was published under each tag. To put it another way, for every tag, look through all the articles it is related to and fin...

MySQL max_allowed_packet param whats the catch?

I need to increase the max_allowed_packet param, to fit some theoretically very large items. If I set this param to say 10M, what price if any am I paying compared to setting it to 1M or 4M. Thanks for any input! Tomas ...

Merging MediaWiki contents together

Currently I have two MediaWikis, one a slightly older version than the other. I want to merge the contents of both together, without eliminating duplicate pages. So far the best option I can think of is to use a bot (like pywikipedia) to go through all the pages of one wiki, and try inserting them into the other, renaming duplicate pag...

Disappearing Foreign Keys in phpMyAdmin

I am creating a new table inside mysql and I am trying to add a foreign key constraint to one of the fields. CREATE TABLE `onlineorder` ( `receiptid` varchar(10) NOT NULL default '', `delivereddate` date default NULL, `cid` int(10) NOT NULL, `card#` int(10) default NULL, `expire` date default NULL, PRIMARY KEY (`receiptid`...

backing up a huge mysql table using php and a cronjob

I'm working on developing a regular dump of our database. I'm using this script to create the backup and then feeding it through a regular cron job. In the end we end up with a text file as well as an email archive of everything. The problem we've encountered is the size of two of our tables. They each have 60k fields and grow daily. ...

Way to select rows which fall on a specific day?

Is there a way in MySQL to select rows which fall on a specific day, as in Mondays, using a date column? ...

Hash Collision - what are the chances?

I have some code on my PHP powered site that creates a random hash (using sha1()) and I use it to match records in the database. This is to obfuscate things like id's in query strings which can (and usually are) sequential, and I don't want anyone changing it in the query string to get other information. What are the chances of a collis...

Are there Javascript bindings for MySQL?

I want to access a MySQL database directly from Javascript in an HTML page in Firefox. Does such a library exist? To be very clear CGI+AJAX will not work Some background: I want to create something like a GUI front end for a MySQL database (that's not what it is but it's close enough). I'm thinking about doing this as a local HTML pag...

How do I relate one table to many different tables?

I have a list of tables i.e. student, teacher, staff, dept. and so on and each of these tables have comments specific to them. Now one record in a table can have one or many comments that shows it's a one to many relation from any table to comments table. I don't know what the best way is to relate comments table to each of these. If I p...

How to call a stored procedure from iReport?

I'm trying to call a stored procedure that receives a parameter from the iReport plugin wizard of Netbeans 6.1, how can I successfully accomplish this task? Other technical details are: using MySQL 5.0.51a-17, and iReport designer 1.0. Thanks! ...

Include ib_logfiles in backup?

The short question: Is it safe skip ib_logfile* files while creating custom-made backup of MySQL installation with InnoDB engine used? Custom-made backup is just copy all (or subset of) /var/lib/mysql + /etc/my.cnf to safe place. As I know ib_logfile* files are recreated by MySQL on start + the files are really huge, so that may not be...