mysql

pdo mysql select statement working on one table while it is not working on other

I am having a strange problem. I am using PDO prepared statement. I have two tables with the name of TABLE1 AND TABLE2. TABLE1 is copied from another db with its data. TABLE2 is created using phpmyAdmin, Both Tables are in the same Database. I am running a Select statement using PDO prepare and its working fine on TABLE1 (which is...

MYSQL query using variable as table name in LEFT JOIN

SELECT var1,var2,var3,table_name FROM table1 LEFT JOIN table_name on var3=table_name.id Meaning I want to dynamically left join table, depending on value of table_name from table1, since var3 is taken from there. But the above query results in table table_name does not exist My mistake of mysql limitation? ...

CodeIgniter/PHP Active Record won't increment an integer

Hi folks Here's my query, in CodeIgniter's Active Record: function calculate_invites($userid) { $this->db->where('id', $userid) ->update('users', array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE); } The fields invites and sentinvites are both integers but are set to 0 after the function is r...

How to ask database to automatically reassign a certain value in a table after 24 hours?

Let's say a player's energy is recorded in a table as "20". As he engages in mission, his energy decreases and reaches 0. However, it would be replenish back to "20" the following day. How do the database detect that a new day has arrive and then automatically assign some value in a certain table? ...

PHP, MySQL, One page Website

Hello, at my work we have a system my boss developed where we have one page (index.php), and the different pages are stored within a database instead of different page files. I was wondering if anyone knew any good tutorials on how to do this? Or if any of you would be able to help me in code it up? ...

"Order by desc" in reverse order?

Welcome, I'm wondering is it possible to reverse returned data in sorting "order by desc" but i want that data in reverse order. For example, i got table with values ID 1 2 3 4 And i do Order by ID ASC LIMIT 3 I got 1 2 3 When i do Order by ID DESC limit 3 i get 4 3 2 I would like to have 3 2 1 So i would like to order by...

Search database for offensive words

I am looking on running a search on my database at set intervals for a list of words I consider offensive (because I am an authoritarian dictator and I hate free speech - I rule with an Iron fist). How would I most efficiently search my database for a list of keywords? The two columns I intend to search are indexed as Fulltext. If anyo...

Handling IF condtions in MySQL

I have a query that based on various ids within a table should return different results.. So for example: Table 'orders' product_id item_id extra_id something_id I'd like return a result based on the values of these, such as IF item_id != 0 'ITEM' ELESEIF product_id != 0 'PRODUCT', etc. Does anyone know how to do this? Thanks! ...

MySQL naming question.

How do you rename a MySQL table in PHPMyAdmin? (SQL command?) Are MySQL table names case-sensitive when working with PHP? ...

Recursive MySQL query

My database schema looks like this: Table t1: id valA valB Table t2: id valA valB What I want to do, is, for a given set of rows in one of these tables, find rows in both tables that have the same valA or valB (comparing valA with valA and valB with valB, not valA with valB). Then, I want to look for rows with...

MySQLi Prepared Statements?

Hi, I have decided to take the plunge into the improved MySQL by using MySQLI . Problem is i cannot find any in depth yet simply put tutorials online. The ones i have found are very short and or does not really explain anything. I know you have the php website but to tell you the truth it is really not a easy tutorial to follow, it's a...

Executing unix commands from mysql

When I am running mysql in the terminal I can do something like \! python ~/run.py to run the the file. However when I copy this to php and do mysql_query it doesnt work. ...

using autosuggest to fill in an input text field after user enters their input, using jquery.

I am trying to use the autosuggest plugin of jquery to take a users input, jquery that input to a php mysql script to get information, then replace the users input with what was retrieved from the jquery request. Now this should stump you all for a minute. first off...if I replace the returned text from the autosuggest script with jus...

MySQL Database synchronization

Is there any free MySQL synchronization tool out there? I need to synchronize the database structure across servers. Data synchronization is not necessary (but is a plus). It needs to be free (for non commercial use), not a free trial. Edit: None of the answers so far has worked, were free, or a suitable to my needs. ...

In RDBMS, is there a formal design principle for Concrete objects, such as Course vs CourseSession?

In designing RDBMS schema, I wonder if there is formal principle of concrete objects: for example, if it is Persons table, then each record is very concrete and unique. Each record in fact represents a unique person. But what about a table such as Courses (as in school). It can have a description, number of units, offered only in Autu...

A function to capture all MySQL errors?

Hi, Does anyone have a PHP function that for example if a mysql_error() happens due to well a MySQL error it will not output it? By not output it I mean rather it not show the error on live site as I will use it with another function I have that would work a treat if I had a MySQL error function. I am just finding it so annoying as I ...

How can I SELECT+INSERT in the same mysql query?

I have a php script that process keywords from a mysql table "keywords" (columns: id - keyword) and then it saves data into another table "data" (column: id[foreign key keywords.id] - dataname - datavalue). My problem is that when the script is ready to save the data I only have the keyword and not the id. So is there a way I can get t...

DB-API with Python

I just spent the better half of my day trying to figure this one out so please for the love of god, help me. I'm trying to insert some data into a local MySQL database by using MySQL Connector/Python -- apparently the only way to integrate MySQL into Python 3 without breaking out the C Compiler. I tried all the examples that come with ...

MySQL: how should I draft this database?

I'm designing a plugin for a high traffic forum. What I am doing is listing related threads using a search API, which has a maximum of 800 searches per day What I'm wanting to do is create a database to store the results, cache them for one day so it will be used instead of the API. Would a table layout such as this be optimal: Tabl...

How to optimize a 'col = col + 1' UPDATE query that runs on 100,000+ records?

See this previous question for some background. I'm trying to renumber a corrupted MPTT tree using SQL. The script is working fine logically, it is just much too slow. I repeatedly need to execute these two queries: UPDATE `tree` SET `rght` = `rght` + 2 WHERE `rght` > currentLeft; UPDATE `tree` SET `lft` = `lft` + 2 WHERE `lft...