mysql

PHP - database not selected. What is wrong with my code?

Hi, I am learning PHP and tried to connect to MySQL. Altough I am using select DB, is still reports "No database selected". What is wrong, please? Thanks. <?php $user="test"; $pass="aaa"; ConnectToDb(); function ConnectToDb() { $pripojeni=mysql_connect('localhost',$user,$pass); $selectedDB=mysql_select_db('1a'); if($query=mysql_qu...

PDOStatement::bindParam() not setting AI value from MySQL insert?

I have a simple insert statement using PDO php class. the 'id' column is identity (doy) with autoincrement. $statement = $db->prepare('INSERT INTO demographics (id,location_id,male,ethnicity_id,birthyear) VALUES (:id,:location_id,:male,:ethnicity_id,:birthyear)'); $statement->bindParam(':id',$demo->id,PDO::PARAM_INT,4); $statement->b...

how can i set up a uniqueness constraint in mysql for columns that can be null?

I know that in MySQL, UNIQUE constraits don't treat NULL values as equal. So if I have a unique constraint on ColumnX, then two separate rows can have values of NULL for ColumnX and this wouldn't violate the constraint. How can I work around this? I can't just set the value to an arbitrary constant that I can flag, because ColumnX in m...

Comma Seperated Values and LIKE php/mysql Troubles

The Set up This is more or less a follow up question to something I had previously posted regarding comma separated values (explode,implode). Here's the scenario which has been stomping me the last few days as I'm a noob--sorry for the lengthy post. I'm passing a variable via the url (index.php?id=variable), I then check the database t...

Inserting random characters to MYSQL Database

I want to add 100 entry to users table numbers field, random characters length is 10, all entry should be unique as well. How can i achieve this using MYSQL query code ? Or do i need to use PHP ? Help me with code snippets please. Thanks. ...

How to call MySQL stored procedure from Rails?

Created a simple stored procedure in MySQL: CREATE PROCEDURE `proc01`() BEGIN SELECT * FROM users; END Start Rails console: $ script/console Loading development environment (Rails 2.3.5) >> User.connection.execute("CALL proc01") => #<Mysql::Result:0x10343efa0> Looks good. BUT, any more call to the same stored procedure via the exi...

SQL Manager for MySQL - select inserts empty row

Hi, I have a very weird situation here. During development I discovered that one of my tables got more and more empty rows (the Id field is auto-incremented and was set). No insert statement was run from my code. I use SQL Manager 2010 Lite for MySQL to inspect the data, and it turns out that when I Execute the select statement from th...

Facebook App : Problem with storing user info

I want to store basic user info like name and proxied email into my MySQL database. Here's my code $facebook = new Facebook($appapikey, $appsecret); $user = $facebook->require_login($required_permissions = 'publish_stream','status_update','email'); $con = mysql_connect("xxxx","xxxxx","xxxxx"); if (!$con) { die('Could not connect: '...

MySQL, merging 2 or more tables before execute SELECT DISTINCT query?

I want to calculate how many unique logins from 2 (or probably more tables). I tried this: SELECT count(distinct(l1.user_id)) FROM `log_1` l1 LEFT JOIN `log_2` l2 ON l1.userid = l2.userid; But it gives me result of l1. If I didnt put l1 on li.userid (distinct), it said "ambiguous". How do I combine the table, and then select uniq...

Union Distinct rows but order them by number of occurrences in mysql

Hi I have the following query: SELECT o.id,o.name FROM object o WHERE ( o.description LIKE '%Black%' OR o.name LIKE '%Black%' ) UNION ALL SELECT o2.id,o2.name FROM object o2 WHERE ( o2.description LIKE '%iPhone%' OR o2.name LIKE '%iPhone%' ) Which procude the following: id name 2 ...

WHM/CPANEL MySQL keeps recompiling during upcp

Every night, Cpanel keeps recompiling MySQL. Here's the output from the logs. I've even tried forcing mysql to reinstall, but still keeps recompiling. MySQL works fine, but this is putting a lot of load on the server, and if it fails to recompile correctly, down goes MySQL, which is not something I'm prepared to wait for. During the rec...

How to use Triggers for Logging History of database change in MySQL?

How to use Triggers for Logging History of database change in MySQL? If yes, then is it possible to create a sepearte db for trigger tables for tracking history of other Db tables?? ...

Why is the index on s not used for sort here?

Setup: mysql> create table test(id integer unsigned,s varchar(30)); Query OK, 0 rows affected (0.05 sec) mysql> insert into test(id,s) value(1,'s'); Query OK, 1 row affected (0.00 sec) mysql> insert into test(id,s) value(1,'tsr'); Query OK, 1 row affected (0.00 sec) mysql> insert into test(id,s) value(1,'ts3r'); Query OK, 1 row affec...

mysql select update

Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID 1 1 1 2 1 3 2 4 2 5 2 6 Need Table a to have a comma separated list as given in table b. And then table b will become obsolete: Table a ID RelatedBs 1 1,2,3 2 4,5,6 This does not rund through all records, but just ad one 'b' to 'table a' UPDATE a, b SET r...

mysql Command timeout error

I am converting my database from sql server 2005 to mysql using asp .net mvc. I have bulk data in sql server(around 4 lakh records), But i am facing command timeout/wating for comand timeout error which when i search on google can be given 65535 as its highest value Or can be given 0 if someone wants that comand should wait for unlimite...

php database connection errors

Hello all, im hoping someone can help me quickly with a question i have. As site i have build is occasionally returning with the error Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in Now at first i thought this was happening as i hade...

PHP Login, Store Session Variables.

Yo. I'm trying to make a simple login system in PHP and my problem is this: I don't really understand sessions. Now, when I log a user in, I run session_register("user"); but I don't really understand what I'm up to. Does that session variable contain any identifiable information, so that I for example can get it out via $_SESSION["user...

what is the mysql query to perform frequency ranking

Hi, am looking for a query which will perform frequency ranking, so that the record which has maximum occurances of supplied "key word" will be listed top in the result. my fields in the table are text and id. Can any one help me in this. Thanks in advance. ...

How to filter MySQL SELECT by an aggregate function?

SELECT h11, HA11 FROM florin.h11 WHERE (3>d1 AND 3<d2) OR (3>d1 AND 3=d2 AND id=MAX(id)) UNION (3=d1 AND 3<d2 AND id=MIN(id)); Here a screenshot of my table stucture: ...

MySQL optimized sentence

I have a simple table where I have to extract some records. The problem is that the evaluation function is a very time-consuming stored procedure so I shouldn't to call it twice like in this sentence: SELECT *, slow_sp(row) FROM table WHERE slow_sp(row)>0 ORDER BY dist DESC LIMIT 10 First I thought in optimize like this: SELECT *, sl...