mysql

php & mySQL: Query does not use index in table join

Hi, I am trying to list all the book_sales information for a particular book author. So I have a query and it's not using Index to lookup records. The following is my tables structure: -- Table structure for table `books` CREATE TABLE IF NOT EXISTS `books` ( `book_id` int(11) NOT NULL auto_increment, `author_id` int(11) unsigned...

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

i've been trying to set up a forgot password facility on a website which i am building but each time i try to load the page i am greeted by the above error. how do i go about resolving this? here is the code i have so far... <?php if (array_key_exists('forgot',$_POST)) { $email = $_POST['email']; mysql_selec...

MySQL triggers cannot update rows in same table the trigger is assigned to. Suggested workaround?

MySQL doesn't currently support updating rows in the same table the trigger is assigned to since the call could become recursive. Does anyone have suggestions on a good workaround/alternative? Right now my plan is to call a stored procedure that performs the logic I really wanted in a trigger, but I'd love to hear how others have gotten ...

Reasons why you wouldn't use a foreign key? [php + MySQL]

I'm working on an old web application my company uses to create surveys. I looked at the database schema through the mysql command prompt and thought the tables looked pretty solid. Though I'm not a DB guru I'm well versed in the theory behind it (having taken a few database design courses in my software engineering program). That being...

Making a local connection between a mysql database and php

I already have the mysql database made, I just need to connect php to mysql locally but I don't know the php commands for that. cheers ...

selecting consecutive numbers using SQL query

Here is a theater seats booking plan. Seat No Status 1 Booked 2 Available 3 Available 4 Available 5 Available 6 Available 7 Booked 8 Available 9 Available 10 Available If someone wants to book 6 tickets, he will get Seat No. 2 to 6 and seat No. 8 And if someone wants to book only 5 tickets, he will get Seat No. 2 to 6 How do I know u...

LEFT JOIN or REGULAR JOIN, and how to compare MySql table to an array? Need performance!

I have six tables: t1, t2, t3, t4, t5, t6. And I also have one main table: main_table. TOTAL 7 TABLES! Now, I am using SOLR for the searching of classifieds, and the results from solr are put into an array. The array results are ID:nrs which I use to match agains the same ID:s in MySql. The first column of ALL tables in MySql is called...

how to prevent rapid page request in php

hey these days im searching internet to secure my codes and my websites , and one point that i crossed and couldn't find a good and easy to learn solution was how to prevent rapid page request or in easy term DDOS ( not exactly that ) . its really likely to happen if some bot or hackers trying to ddos a page , i want a way to s...

how to add new column to existing composite primary key

I have encountered a problem in that I already have a composite primary key in a MYSQL table. But now I have added another column to that table and due to some requirement changes, I have to modify that composite primary key in such a way that I need to add that previously mentioned column to that composite primary key list. Can anyone t...

Count and group non-empty values in MySQL

I need to count the non-empty (by which I mean a string containing at least 1 character) rows grouped by a particular ID. Eg. my data might look like this: form_id mapping 1 'value_1' 1 '' 1 'value_2' 2 '' 2 NULL 3 'value_3' and I want to count the non-empty values for each form, so I ...

MySQL fetch next cursor problem

Hello, I have a problem fetching values from a MySQL cursor. I create a temporary table which is a mere copy of another table (the original table has a variable name, that's passed as the procedure's parameter, and because MySQL doesn't support variable table names, I have to create a copy - can't use the original directly). The temp...

php time function

what is wrong with this sql query? he is crying on NOW() :( ("INSERT INTO " . PREFIX . "messages (from, to, title, message, date) VALUES (" . $from . ", " . $to . ", " . $subject . ", " . $message . ", NOW())"); ...

Foreign characters turn into garbage in mysql

I am in the U.S. I have the following line in my web page: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> And my MYSQL table is MyISAM latin1_swedish_ci But when someone fills out a form with a foreign character it gets stored in MySql as garbage. An example would be an e with accent over it, etc. - something...

Why would a script not like using MySQLi but is fine with MySQL?

I'm having some issues using mysqli to execute a script with SELECT,DELETE,INSERT and UPDATE querys. They work when using norm mysql such as mysql_connect but im getting strange results when using mysqli. It works fine with a lot of the SELECT querys in other scripts but when it comes to some admin stuff it messes up. Its difficult to e...

How do I find my local host and username on mysql?

I need to open my database through PHP but I need to know my username and the name of my localhost, and i don't know them. When i used mysql and did my database it just asked me directly for a password. ...

Mysql query problem

I have tables: users with the fields id, premium votes with the fields userid, date. How do I select ALL THE VOTES from ALL USERS FROM TODAY only when premium = 'yes' ? ...

Is there any reason to use XML/XSLT when using a PHP/MySQL App?

I have been making HTML/PHP/MySQL database apps for quite a while now. I have avoided using XML/XSLT in any application since I just pull the data out and format it within my PHP script, and display it. Assuming I am not wanting my data to be portable to other people's applications (via XML), is there any reason to implement an XML/XSL...

SQL: Select SUM of all children records recursively

I have a table that has a one to many relationship with itself. Each record can have n number of children from that same table. For example create table folder ID: Number 20 PK PARENT_ID: Number 20 FK references folder.ID SIZE: NUMBER 20 ... Given an ID, I want to select the SUM(SIZE) of all folder records recursively. The target d...

How to change root password to an empty one?

How can I change the root password to an empty one in MySql? The following gives "Access denied for user 'root'@'localhost' (using password: YES)" error. I'm sure I've typed my password correct (it's only 123456) mysqladmin -u root -p'123456' password '' I've run this sql successfully but I can still access with my password 123456 an...

Creating MySQL and SQLServer compatible objects

I have a need to support two separate database engines - MySQL and SQL Server. I do not want to maintain two different sets of scripts to create database objects (tables, views, stored procedures etc...), if possible. I wanted to find out if someone has experience in doing such a thing and what were the learnings. Any links to articles/...