mysql

How to change the foreign key referential action? (behavior)

When table was set up with a column that has a foreign key and is set to cascade (delete child when parent is deleted) what would the sql command to change this to be restrict? (can't delete parent if it has children) ...

How to return different strings from a Boolean type in MySQL?

If I have a column set up as Boolean in MySql, a query returns the value as either 0 or 1. Is it possible to do something like this SELECT `bool_value` AS "yes" OR "no" What I mean is, return two different strings based on whether it is true or false. ...

php:count data from db then show at other page

dear all..i have this data inside DB: line model serial fa01 kd-g335ud 105x0001 fa01 kd-g335ud 105x0002 fa01 kd-g335ud 105x0003 //up to 20pcs or regardless of the number of goods in the db fa02 kd-r311ed 105x0001 fa02 kd-r311ed 105x0002 //up to 20pcs or regardless of the number of...

Which MySQL database engine is better for storing sessions and session data: MyISAM or InnoDB?

Pretty straightforward question. I use InnoDB for everything else, for a couple of reasons. Is it a performance hit over MyISAM for a 'high-traffic' table? ...

Retrieve the last 10 records from mysql database table, problem.

I have a weird problem. When I run this script I get 10 records from the database but they are all exactly the same. I have no idea what I am doing wrong or how to fix it. Please help me. I have tables AMCMS_highscores , AMCMS_users , AMCMS_games I want to look inside the AMCMS_highscores table, get the last 10 records but only where th...

Update/Increment multiple mySQL columns in one query

I have this query, which works... UPDATE `contacts` SET `calls_to`=`calls_to`+1 WHERE `contact_no` = '0412345678'; What I also want to do is add a value to the cost field. From my understanding, the way to do this would be... UPDATE `contacts` SET `calls_to` = `calls_to`+1, `cost_to` = `cost_to`+0.25 ...

Do I really need to do mysql_close()

Do I really need to do mysql_close()? Why or why not? Is there a trigger that closes the link after mysql_connect even if I don't do mysql_close? ...

mysql:show date from datetime

hello all... i have a field inside table inspection,it is inspection_datetime. the type of field is datetime, so that make the data like yy/mm/dd hh:mm:ss. my question is how do i do if i want to show date only from the data? ...

Optimize SQL Query

Hi, I have following query on a MySQL DB: SELECT * , r.id, x.real_name AS u_real_name, u.real_name AS v_real_name, y.real_name AS v_real_name2 FROM url_urlaube r LEFT JOIN g_users u ON ( r.v_id = u.id ) LEFT JOIN g_users x ON ( r.u_id = x.id ) LEFT JOIN g_users y ON ( r.v_id2 = y.id ) WHERE ( ( FROM_UNIXTIME( 1283205600 ) >= r.from AN...

ORDER BY not working in MySQL 5.1

Hello, guys. I have a problem with sql query in php: select user, name, outlet, switch, port, vlan, mac, status from access where user like '%' and name like '%' and outlet like '%' and switch like '%' and port like '%' and vlan like '%' and mac like '%' and status like '%' order by 'user'; When r...

count and search string from data array

Hello.. I have a database table as follows: line model serial range serial fa01 kd-g335ud 105x0001 105x0001-105x0200 fa01 kd-g335ud 105x0002 105x0001-105x0200 fa01 kd-g335ud 105x0003 105x0001-105x0200 fa02 kd-r311ed 105x0001 105x0001-105x0500 fa02 kd-r311ed 105x0002 105x0...

Encryption Key Management Software and Transparent Data Encryption MySQL

For PCI compliance, is there any recommended Encryption Key Management Software? Open source preferable, but commercial is ok too. Is there a tool or software that provides both? ...

MySQL autoincrement problem

I have a table with autoincrement field, I have for example 1,2,3 values, when I insert 4 and delete it the next will normally be 5. I delete 5 and after a long time , say 1 week when I insert new record the next is again 4. Can somebody tell me why this happen , why when I insert a new record after a long time its getting the last inse...

how to show alert "data already exists"

hello.i newbie this my first project,I don't know how to resolve any problems about the repetition of data i have an input page. it consist of 2 textfield: Model, Serial, and one combobox: 1. line. i want if there is input twice, I mean here is a double input data, will be out warning "data already exists". how do i do that?i ...

MySQL condition

I'm still pretty new with MySQL and I don't know the best way to do this. I have a table with incremented values, and if the values exceed a certain limit, I'd like to know. So lets say I have this table with a current column and capacity column. A row in current is incremented by user input and I want to know when the value in a curren...

How to make PHP use the right charset?

I'm making a KSSN (Korean ID Number) checker in PHP using a MySQL database. I check if it is working by using a file_get_contents call to an external site. The problem is that the requests (with Hangul/Korean characters in them) are using the wrong charset. When I echo the string, the Korean characters just get replaced by question mark...

Is this line of PHP good enough to prevent MySQL injection?

I have the following code that adds a record to my MySQL database via PHP: Contact is just a plain string. $contact = mysql_real_escape_string(stripslashes($_POST["contact"]), $con); $sql="INSERT INTO custom_downloads (contact) VALUES ('$contact')"; Is this good enough to prevent any sort of SQL injection attacks? What else can I do ...

Problem with adding foreign key to table in mySql

I get error 1452 when trying to do this: ALTER TABLE test.potovanja ADD CONSTRAINT usr_ind FOREIGN KEY (username) REFERENCES test.users (username) (Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails (test., CONSTRAINT #sql-1110_2_ibfk_1 FOREIGN KEY (username) REFERENCES users (username))). Reference key...

How would I use ON DUPLICATE KEY UPDATE in my CodeIgniter model?

Hi folks! I have a CodeIgniter/PHP Model and I want to insert some data into the database. However, I have this set in my 'raw' SQL query: ON DUPLICATE KEY UPDATE duplicate=duplicate+1 I am using CodeIgniter and am converting all my previous in-controller SQL queries to ActiveRecord. Is there any way to do this from within the Activ...

Select from 4 tables with joins and IN

I'm have 5 tables. First products like: id | country_ids | category_ids | users_ids 1 | 1,4,6 | 4,5,6,70 | 5,6,9 2 | 5,6,3 | 4,8,2,11 | 1,5,8 Second countries like: c_id | c_name 1 | Åland Islands 2 | Antarctica ... Third categories like: cat_id | cat_name 2 | Small 4 | Large ....