mysql

How to use PHP Session to View MYsql Database Tables?

Hi there! I am currently trying to create a PHP script whereby there is already a login script created and the user that successfully logs into the home.php is able to view the tables of the database he is logged into. Is there any ways of retrieving the tables using the mySQL query like "SHOW TABLES"? Here are some of my codes: <?php...

Security issue / sql injection with mysql collation?

Perhaps I don't have enough of an understanding of this yet, so I'm looking for a little direction. All of our tables show a collation of latin1_swedish_ci. Here's what I see in the mysql variables: collation connection utf8_general_ci (Global value) latin1_swedish_ci collation database latin1_swedish_ci collation server latin1_swedis...

PHP/PDO: Prepared statements don't work when creating a table?

When I am using a PDO prepared statement, and use it to plug in a table name to the query it fails, a quick example: $stmt = $dbh->prepare("CREATE TABLE ? (id foo, int bar,...)"); $stmt->execute(Array('table_foobar')); All it does is replaces ? with 'table_foobar', the single quotes don't allow creation of the table for me! I end up ...

How do I limit the result of a subquery in MySQL?

Is there a way of limiting the result of a subquery? The sort of thing I'm trying to achieve can be explained by the query below: SELECT * FROM product p JOIN ( SELECT price FROM supplierPrices sp ORDER BY price ASC LIMIT 1 ) ON (p.product_id = sp.product_id) The idea would be to get only the lowest price for a particu...

MySQL event scheduling update query

I am just getting to grips with the event scheduler in MySQL and I am writing a query to update a column on the same date each year. The problem I am having is working out the best way to structure my update query. Every user has a value in column_x that is a varchar field in the format of int/int. These values range from 7/1 to 7/11, ...

which indexes multiple field?

Hello there. I have a question for field indexing and I am not really sure how to do it. Which indexes should be multiple field index and which "stand alone"...sorry for my terminology :). I have a table where only insert,delete and select will be present, only a104 will be updatable, other fields will be "read only"... So I have 106 fi...

mysql fails to start and i can't see why

Hi all. After a reboot, mysql is failing to start. Before i rebooted i was fooling around with the /etc/mysql/my.cnf file, trying to change my default character encoding from utf-8 to latin1. As far as i can tell, i've undone my changes (thinking they were probably the result of it failing to start) but i'm not sure as i didn't make a...

How to restrict '♥♣' characters in text box.

Hi All, How can i restrict '♥♣' like characters from saving into database. If these characters appear in name text field, a error message should be thrown. I am using ruby on rails. Thanks, Anubhaw ...

Should I calculate percentages in MySQL or in the application?

I'm writing a Rails app that does a lot of calculations on imported pay-per-click advertising data. The imported logs, which contain records about impressions, clicks, conversions, etc. are all stored in one massive log table, which then needs to be joined with a conversions table to calculate cost per conversion, conversion rate for eac...

How to write a sql query to figure out if a value falls within a range

tableA contains {id, fromPos not null, toPos} fromPos and toPos denotes a range of values for a particular row toPos is a nullable field and has the following values tableA (1, 5) // means any position greater than or equal to 5 tableA (2, 5, 10) // means any position between 5 and 10 (inclusive) tableA (3, 6) tableA (4, 7, 9) ...

Upload images using a folder in php

Hi, I have a folder with full of images.But I have to upload the images to mysql database. How can I do it using php code? Regards, Rekha ...

MySQL greater than or equal to operator is ignoring its or equal to obligation

If a price in a row is 38.03, then the following search restrictions should all return the row containg the result. WHERE price >= '38.02' AND price <= '38.03' (This works) WHERE price >= '20' AND price <= '100' (This works) WHERE price >= '38.03' AND price <= '38.03' (This doesn't work) WHERE price >= '38.03' AND price <= '100' (Thi...

MySQL - How do I efficiently get the row with the lowest ID?

Is there a faster way to update the oldest row of a MySQL table that matches a certain condition than using ORDER BY id LIMIT 1 as in the following query? UPDATE mytable SET field1 = '1' WHERE field1 = 0 ORDER BY id LIMIT 1; Note: Assume the primary key is id and there is also a index on field1. We are updating a single row. We are ...

using a column's value in calculation in mysql query

I have this code which should (hopefully) get the closest results to a given location: $sql = "SELECT *, lat as LAT, long as LONG FROM mellow_listings ORDER BY SQRT(((".$long."-LONG)*(".$long."-LONG)) +((".$lat."-LAT)*(".$lat."-LAT))) ASC LIMIT 0,10"; for some reason it isn't working at all. I think its because I'm incorre...

setting multiple column using one update.

How to set multiple columns of a table using update query in mysql? ...

how to write regex starts and ends with particular string?

How to write regex for this paricular situation. Here letters in [] is not fixed but letters without [] is fixed. http://www.abc.com/fixed/[any small letters]/[anyletters]/fixed.html ...

Arabic being displayed in giberish and question marks

Hey, I created a php website that would simply load the text from a mysql database, when I open it in a browser the Arabic text is presented in gibberish but then when I change the encoding of my browser to UTF-8 it's displayed properly, how can I force the encoding to be UTF-8 so users don't have to change it? The menu part of the webs...

Overlapping date range MySQL

Hi guys, I have the following data; ID startDate endDate ----------------------------------------------- 1 2010-03-01 10:00:00 2010-03-01 12:00:00 2 2010-03-01 12:30:00 2010-03-01 15:30:00 3 2010-03-01 15:30:00 2010-03-01 18:30:00 What I want to do is check that a start and end date don't fall inside ...

Mysql logs only for one database

Hot to configure mysql to log information, only for specific database or table? For example i need to log authentification requests from Postfix to mysql. Thanks ;) ...

select categories with parent name from one table

Hello, I got an existing products database which I'm writing an administration tool for (in PHP). The database contains the following "categories" table: Table Categories -------------------- PK | id FK | parent_id | title Now the foreign key "parent_id" contains an id taken from the same table, or "0" if it's a topmost category. ...