mysql

PHP and Multiple DB Selects

I've got two tables from which I need to extract information, but the data from the second table depends on the information I get from the first one. Is there an easy way to handle this? <?php mysql_connect('localhost', 'root', 'root') or die(mysql_error()); mysql_select_db('stadium') or die(mysql_error()); $result = mysql_query(...

Connection with MySql is being aborted automaticly. How to configure Connector/J properly?

I read this advice from error message: You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. I'm using Spring and JPA. W...

mysql using sum and group by clause

I have the following code.The query woks well in mysql but it does not work when integrated with java.Please check the code.Sum is not calculated correctly for all the columns.Please Help .Thanks a lot import java.io.*; import java.sql.*; public class Sum11{ public static void main(String[] args) { System.out.println("S...

Images in MySQL

I have a blob column in my table. How do I insert an image into it and how do I retrieve it onto the picturebox on a windows form? ...

MySql copy profiling data to table

Hello everyone. I want to copy profiling data to a table I create in MySql. I want the table to contain the exact data that I get from the command SHOW PROFILES; For example, if I have this: mysql> show profiles; +----------+------------+--------------------------------+ | Query_ID | Duration | Query ...

Optimizing MySQL query for fetching data using time range

I'm building a line chart for a product sales report by using the Google Chart API and are separating the data on a per day basis with basically running the same query in a loop for each day using UNION ALL as glue. E.g. A report for a whole year will repeat the query, using UNION ALL 365 times. I'm guessing this is not a -best pract...

MySql Group function error

select nume,model,sum(km_sosire-km_plecare) as 'km_parcursi' from masina m inner join (foaie_parcurs f inner join angajat a using(id_angajat)) using(id_masina) where sum(km_sosire-km_plecare)>100 group by a.nume,m.model order by sum(km_sosire-km_plecare); Error: Invalid use of group function Why? Thanks. ...

warning problem: expects parameter 1 to be mysqli_result

I get the following warning listed below and I was wondering how do I fix it Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given on line 65 The code is around this section of PHP code listed below. I can list the full code if needed. // function to retrieve average and votes function getRatingText(){ ...

How do you join (implode) a MySQL Array?

The implode() function works on normal arrays, but it doesn't work on arrays created with mysql_fetch_array (I also tried mysql_fetch_row) How do you get them to work? Defined Above: $friends = mysql_query("SELECT * FROM friend WHERE u1='$userinfo[username]' OR u2='$userinfo[username]' "); And further down: $friendsrow = mysql_f...

Is there a secure way to set up a mysql root password?

In this how-to geek article, the author talked about using mysqladmin -u root -h host_name password “newpassword” To set a new password. A person replied that that may leave the password in the shell's history file, and suggested using mysql -u root mysql mysql> SET PASSWORD FOR root@localhost=PASSWORD(’newpasswordgoeshere’); but a...

MySQL & PHP - Not unique table/alias

I get the following error listed below and was wondering how do I fix this problem. Not unique table/alias: 'grades' Here is the code I think is giving me the problem. function getRating(){ $dbc = mysqli_connect ("localhost", "root", "", "sitename"); $page = '3'; $sql1 = "SELECT COUNT(*) FROM articles_grades WHE...

Using an Alias in SQL Calculations

Why won't this query work? SELECT 10 AS my_num, my_num*5 AS another_number FROM table In this example, I'm trying to use the my_num alias in other calculations. This results in unknown column "my_num" This is a simplified version of what I am trying to do, but basically I would like to use an alias to make other calculations. My ca...

DB a table for the category and another table for the subcategory with similar fields, why?

I recently joined a new company and the development team was in the progress of a project to rebuild the database categories structure as follows: if we have category and subcategory for items, like food category and italian food category in food category. They were building a table for each category, instead of having one table and a l...

PHP & mySQL: When exactly to use htmlentities?

Hi all, PLATFORM: PHP & mySQL For my experimentation purposes, I have tried out few of the XSS injections myself on my own website. Consider this situation where I have my form textarea input. As this is a textarea, I am able to enter text and all sorts of (English) characters. Here are my observations: A). If I apply only strip_tags ...

Poll system multiple answers

If you would want to make a poll system that supports multiple answers (options) (not just yes/no) how would you do it? How would you structure the db etc? I don't want to limit the answers/options. Some input on this would be greatly appreciated. ...

How do I best combine and optimize these two queries?

Here is my main query which pulls in thread information as one row, it lacks the # of votes and currently I'm pulling that in with a second query. SELECT Group_concat(t.tag_name) AS `tags`, `p`.`thread_id`, `p`.`thread_name`, `p`.`thread_description`, `p`.`thread_owner_id`, `p`.`thread_view...

MARS for MySQL in C#

Today I've implemented a nasty hack in my code where every request to the database opens it's own connection due to the fact that I couldn't find any way to enable MARS (multiple active record sets) when communicating with a MySQL database. In my C# program I do a lot of parallel work, which isn't a problem regarding databases such as M...

In PHP/MySQL should I open multiple database connections or share 1?

I am wanting to hear what others think about this? Currently, I make a mysql database connection inside of a header type file that is then included in the top of every page of my site. I then can run as many queries as I want on that 1 open connection. IF the page is built from 6 files included and there is 15 different mysql queries,...

Rails debugging in production environment

I'm creating a Twitter application, and every time user updates the page it reloads the newest messages from Twitter and saves them to local database, unless they have already been created before. This works well in development environment (database: sqlite3), but in production environment (mysql) it always creates messages again, even t...

MySQL LIKE question

I have a script: $friendnotes = mysql_query("SELECT nid,user,subject,message FROM friendnote WHERE tousers LIKE '%$userinfo[username]%' "); And the content in the "tousers" table of the database: Test Example User That script appears to be working well However, if there is a user called "Test2", it would also display content th...