mysql

How to search for city in a record in MySQL

I have to search user according by city but my problem is that in user table in city field there are two cities like arizona@losvegas, because in registration user can select two cities. So how can I search city by city name? Like if someone searches for all users from arizona... I have done this by using LIKE in SELECT query but I wan...

Taking mysql data backup with php5

I am using php5 and mysql5.- in my local server I want to take mysql database backup ( in my local server ) - just by copying the datafile ( located in mysql server in the folder data ) I have copied a particular table name account.frm file - but it is not working It is showing the table name but it is showing error that ( I check...

Mysql insert and update impressions with PHP

I want to record number of advertisement impressions and clicks per day in database. I'm using PHP to insert and update that data in mysql. The script that display specific advertisement and store data in db looks like: ...count the number of rows in db with this advertisement ID ... if ($total == "0") { mysql_query("INSERT INTO impres...

MySQL select with subquery having replace

So I have a data with format like ;1;;2; and then I need to use this number in a query so I thought I'd convert it to 1,2 and use that in a IN condition. In my table, the result should return 2 rows but instead it is returning only 1 row. My query is like this. The subquery return 1,2 with no problem but only 1 row is retrieve. select ...

Hibernate and Mysql timeout problem, doesn't work with c3p0

Hi, I have been having trouble with Hibernate and Mysql timeout error for a week. Apparently, After my Hibernate/MySQL have been running after 8 hours(which is default timeout value in Mysql), I have the exception. I also added c3p0. But it doesn't help. Please advice Thank you so much Here is my Hibernate Configuration: <property ...

could not display image

When i'm trying to display the image from the database the image is not been displayed didn't know what was the problem,here is my code. show_desc.php <?php $errmsg = ""; if (! @mysql_connect("localhost","root","")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("dbname"); if (isset($_GET['img_name'])) {...

What is the significance of the order of statements in mysql explain output ?

This is mysql explain plan for one of the query I am looking into. +----+-------------+--------+-------+---------------+---------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------+-------+---------------+---------+---------+------...

Python copy MySQL table to SQLite3

Hello, I've got a MySQL table with about ~10m rows. I created a parallel schema in SQLite3, and I'd like to copy the table somehow. Using Python seems like an acceptable solution, but this way -- # ... mysqlcursor.execute('SELECT * FROM tbl') rows = mysqlcursor.fetchall() # or mysqlcursor.fetchone() for row in rows: # ... insert r...

Question on partial keys and an index on a database table

Suppose I have two queries on a database table. The queries are defined in terms of fields used in the query: Query1: depends on f1, f2, and f3 Query2: depends on f1, f2, f3 and f4 I remember reading somewhere that the SQL query engine (mySQL in this case) parses the index tree starting from the leftmost fields in the index. If that...

undefined method `eq' for nil:NilClass with rails 3 and ruby enterprise on ubuntu hardy

I am not sure what causes this error but since I came across this issue in passenger and now in the console as well I am thinking maybe the mysql driver is the problem? Everything works as expected on osx/10.6. It just won't on Ubuntu 8.04 hardy. I nailed down the problem to either the "destroy" method or also when I call a method of a...

Query doesn't work

I get the following error message when I try this query: $query .= "($tid, {$_POST['type']['$i']}, 'Y', NOW())"; 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 (18, , 'Y', NOW())' at line 1 Everything in my code works except this line. I know ...

How to allow users to accept or deny friends using PHP & MySQL?

I was wondering how would I allow a member to accept or deny another member as a friend? How would my PHP & MySQL code look like? Here is my PHP & MySQL code. if (isset($_GET['fid'])){ $friend_id = mysqli_real_escape_string($mysqli, htmlentities(strip_tags($_GET['fid']))); if(isset($site_id)){ $dbc = mysqli_query($mysq...

How to ensure that MySQL rows are unique?

I am trying to insert a row into a MySQL table, with the condition that the row itself has to be unique. So for example, the row would have id, name and address, but we can't have an insert with duplicate name and address. I tried doing a select before inserting, to make sure I don't find the result, but it doesn't seem to be working. I...

MySql - Aggregate function for choosing first choice, second choice, third choice, etc?

Imagine I have the following data in a table called "messages": message_id | language_id | message ------------------------------------ 1 en Hello 1 de Hallo 1 es Hola 2 en Goodbye 2 es Adios (Note that I don't have a German t...

How to make currently selected drop down menu item be preselected from database?

I tried this on my own but couldn't get it to work right. Basically I am making an edit page where a previously submitted post can be edited. On this new page the form is pre-populated with previously submitted data. One of the things that was chosen earlier was a category from a drop down. I am trying to have that previously choden cate...

How do I select multiple tables in one line?? and insert into??

Hi I would like to select multiple table in one query say like below and insert into multiple table: $result = $db->sql_query("SELECT * FROM data1,data2,data3,data4 WHERE person='" .$name. "'"); $row = $db->sql_fetchrow($result); $day = $row['regtime']; $days = (strtotime(date("Y-m-d")) - strtotime($row['regtime'])) / (60 * 60 * 24); ...

SQL Server equivalent of MySQL multi-master replication?

Is there an MSSQL equivalent of MySQL's multi-master replication? If so, is it available in SQL Express 2008? I've also seen it referred to as two node circular replication. Basically, I have an in-office database that I want to be perfectly (relatively :) )in sync with a cloud database (we will have access via VPN). Reads and writes oc...

Echo current number of row

Hi! My $num_rows echos the total row count but I want the current row number. <?php $result = mysql_query('SELECT * FROM texts ORDER BY id desc'); while($row = mysql_fetch_array($result)){ $num_rows = mysql_num_rows($result); ?> <tr class="alt"> <td><?php echo $row['id']; ?></td> <td><?php echo $row['title']; ?></td> <td><a...

How to save DIV tag to MySQL with PHP and jQuery

Hello eveybody, I'm using jQuery + PHP + MySQL My problem is how to save for example this div in my MySQL database using an Ajax call with jQuery to PHP. PS. i know how to send an Ajax call with jQuery to PHP and save variables from this call to MySQL. <div id="id-aaa"> Les ordinateurs, eux, comme on l’a vu, ont un dispositif physiqu...

How to select multiple results for a single row - MySQL

Hello, I have 3 tables; game, platform, game_platform game id name desc ---- ------------ --------- 1 Modern Warfare... Awesome game...... 2 ... ... 3 ... ... platform id name ---- ------------ 1 pc 2 ps3 3 ... game_platform game_id platform_i...