mysql

PHP Web Application: mysql database design best practices question

Hi All, I am currently in a debate with a coworker about the best practices concerning the database design of a PHP web application we're creating. The application is designed for businesses, and each company that signs up will have multiple users using the application. My design methodology is to create a new database for every compa...

Can I avoid to overwrite a column with a NULL value on INSERT query?

I have two different queries in my php page for the same table, the first one is executed if I have two different values for two columns, but in some case, i can use only the first value, can I do it with the same query or should I use two different queries? // query 1 "INSERT INTO my_table (column_1, column_2) VALUES ('$value_1', '$val...

MySQL query is creating a duplicate row

I have never encountered an error like this before. I was using prepared statements when it stared and have tried everything to correct the problem including stripping the form down to it's bare components. The following code, when executed, is creating a duplicate row. $sql = "INSERT INTO inventory VALUES ('','$stocknum','$y...

Help diagnose bizzare MySQL query behavior

Hi, I have a very specific query that is acting up and I could use any help at all with debugging it. There are 4 tables involved in this query. Transaction_Type Transaction_ID (primary) Transaction_amount Transaction_Type Transaction Transaction_ID (primary) Timestamp Purchase Transaction_ID Item_ID Item Item_ID Client_ID Lets...

How to handle new files to process in cron job

How can I check files that I already processed in a script so I don't process those again? and/or What is wrong with the way I am doing this now? Hello, I am running tshark with the ring buffer option to dump to files after 5MB or 1 hour. I wrote a python script to read these files in XML and dump into a database, this works fine. My ...

[Mysql]: select UNIQUE w/ join

I have a series of related tables. Transaction_Type Transaction_ID (primary) Transaction_amount Transaction_Type Transaction Transaction_ID (primary) Timestamp Purchase Transaction_ID Item_ID Purchase_ID (primary) Item Item_ID Client_ID I need to select transaction_type rows based on a time stamp and client_id My query is as foll...

MySQL search for 1,2,3,11,22,33 in field

Can I search for 1 AND 2 AND 3 without getting a false match because 11,22,33 are in the field? A field that has the string = "11,22,33" should then not return any results. ...

Which is faster: char(1) or tinyint(1) ? Why?

Hi all, MY PLATFORM: PHP & mySQL MY SITUATION: I came across a situation where I need to store a value for user selection in one of my columns of a table. Now my options would be to: Either declare the Column as char(1) and store the value as 'y' or 'n' Or declare the Column as inyint(1) and store the value as 1 or 0 This column so...

MySQL: Large VARCHAR vs. TEXT?

Apologies if this is a silly question, could use an opinion: I've got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or TEXT. I'm setting a front-end limit of 3000 characters which means the messages...

SQL Replacement via table

Mysql question: I've got a table A with a column full of sentences. I've got another table B with two columns: words and abbreviations. I want to look through table A's column sentences and if a word from table B's word column matches then replace it with abbreviation. Hope that is clear. Case doesn't matter, I can deal with that. ...

MySQL: ORDER BY stat / age?

I have an int field in my product table called product_stat which is incremented everytime a product is looked at. I also have a date field called product_date_added. In order to figure out the average visits per day a product gets, you need to calculate how many days the product has existed by using the current date and the date the p...

What's the best programming language for large SOA system?

I am working on a relatively big system with: low level C++/C codes dealing with multimedia data(video/audio) a lightweight database, preferably MySQL but I am open to other better alternatives RESTful web service as the front end All the requests will be handled by RESTful interface, low level C++/C codes dealing with the real hard...

How do you simulate memory shortage with MySQL?

I want to know how my system behaves under a high load. To do so I would like to artificially reduce the amount of memory available to MySQL. How should I do this? ...

query the highest latest userid

I have a table with the following. The names are not unique. userid, name 1, dave 2, john 3, mike 4, mike 5, dave I want to return the unique name with the highest userid. ie. 2, john 4, mike 5, dave What is the query to do so? ...

Check mySQL is Correct

Hey SO PHPmyAdmin keeps rejecting this mySQL im pretty sure its right and don't actually need it to run, its uni work and just have to hand in, it looks right to me. the actual error I get is #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '...

What's the impact of NULL on MySQL tables? (InnoDB)

Hello guys, Recently, I've been thinking if it's worth to have 1 table with perhaps a lot of NULL columns or if it's better to have more tables with no NULLs. I've heard that NULL isn't stored on InnoDB, so I was wondering if there is any downside or problem with having a bunch of rows with a lot of NULLs. I have always heard that commo...

Python - automating MySQL query: passing parameter

Hello Everybody, The code in the sequence is working fine, but looking to improve the MySQL code to a more efficient format. The first case is about a function that received a parameter and returns the customerID from MySQL db: def clean_table(self,customerName): getCustomerIDMySQL="""SELECT customerID FROM customer WHERE ...

MySQL: Dump a database from a SQL query

I'm writing a test framework in which I need to capture a MySQL database state (table structure, contents etc.). I need this to implement a check that the state was not changed after certain operations. (Autoincrement values may be allowed to change, but I think I'll be able to handle this.) The dump should preferably be in a human-re...

Unable to connect to MySQL through PHP script when using mysqli or PDO BUT mysql works.

I am facing a weird situation. When I am trying to connect to MySql database using a "mysql" connection, it works. mysql connection string -> mysql_connect($HOST, $USER, $PASSWORD, $DB); But the connection fails immediately fails when I use either "mysqli" or "PDO" mysqli connection string -> mysqli_connect($HOST, $USER, $PASSWORD, ...

MySQL Instrumentation using mysql_proxy

I want a simple way to see what commands are being sent to MySQL. I have several MySQL projects that sometimes have a few messy layers of code. I want something like SQL Server Profiler without all of the bells and whistles. I just need to see the SQL traffic. Not analyze which queries are executed most often. I found MySQL Proxy an...