mysql

PHP/mysql array search algorithm

I'd like to be able to use php search an array (or better yet, a column of a mysql table) for a particular string. However, my goal is for it to return the string it finds and the number of matching characters (in the right order) or some other way to see how reasonable the search results are, so then I can make use of that info to decid...

MySQL select records that sums

Hello. I am using MySQL and PHP. I have a table that contains the columns id and quantity. I would like to retrieve the id of the row that is the last to sum quantity as it reaches the number 40 at sum. To be more specific. I have 3 rows in the database. One with quantity 10, one with quantity 30 and one with quantity 20. So if I sum the...

$data findAll query in CakePHP checking values from second table

Hello there, I have been stumped by CakePHP in how to query the DB in CakePHP and return things to $data only when the $data query table [id] has a matching [sub_id] in a second table a standard query: $data = $this->Table1->findAll(array("Table1.deleted" => "0"), null, "Table1.id DESC", 25, null, 1); But I want to only have values p...

I've got an existing Django app with a lack of database indexes. Is there a way to automatically generate a list of columns that need indexing?

The beauty of ORM lulled me into a soporific sleep. I was thinking maybe some middleware that logs which columns are involved in WHERE clauses? but is there anything built into MySQL that might help? ...

Selecting from multiple MySQL tables

I have a few tables that have similar fields but not exactly the same. The same fields they have are description (text field) and modified (unixtime) I would like to select the last modified items from these tables based on unixtime. I cant use UNION since the tables aren't the same and the multiple table select times out. I've been t...

How to create a MySQL stored procedure from PHP ?

My attempts to query MySQL from PHP with a create statement of a store procedure (SP) have all failed. Is this not possible ? If indeed possible, please give an example. ...

MySQL design with dynamic number of fields.

My experience with MySQL is very basic. The simple stuff is easy enough, but I ran into something that is going to require a little more knowledge. I have a need for a table that stores a small list of words. The number of words stored could be anywhere between 1 to 15. Later, I plan on searching through the table by these words. I ...

MySQL Insert: Test first?

As an example, when inserting a record into a table with a unique index, is it best to test first? e.g., $mysqli->query('SELECT email FROM tblUser WHERE email = '[email protected]'); then make sure 0 rows are returned, then do the insert? $mysqli->query('INSERT INTO tblUser ...'); Or is it better to just skip the test and handle the er...

Best way to store global variables

I'm writing an application in PHP that uses a LOT of global variables that are used throughout the script. Right now, I have a config file that stores a bunch of global variables created by using the define() function, but since I'm going to have so many, would it be better to create a table in the database that is just contains variable...

How do I know how many rows a Perl DBI query returns?

I'm trying to basically do a search through the database with Perl to tell if there is an item with a certain ID,. This search can return no rows, but it can also return one. I have the following code: my $th = $dbh->prepare(qq{SELECT bi_exim_id FROM bounce_info WHERE bi_exim_id = '$exid'}); $th->execute(); if ($th->fetch()->[0] != $ex...

Possible to do a MySQL foreign key to one of two possible tables?

Well here's my problem I have three tables; regions, countries, states. Countries can be inside of regions, states can be inside of regions. Regions are the top of the food chain. Now I'm adding a popular_areas table with two columns; region_id and popular_place_id. Is it possible to make popular_place_id be a FK to either countries ...

Migrating MySQL to PostgreSQL - what features not visible in SQL code will be important?

We're migrating MySQL to PostgreSQL. I can easily audit the schema and the SQL statements used throughout the (REALbasic) program. Most of the SQL is composed by building string variables. I already know about needing to replace our use of SELECT LAST_INSERT_ID() with a SERIAL column with UNIQUE constraint. What, if any, differences b...

MySQL foreign key to allow NULL?

Hi there, I'm piecing together an image website. The basic schema's pretty simple MySQL, but I'm having some trouble trying to represent possible admin flags associated with an image ("inappropriate", "copyrighted", etc.). My current notion is as follows: tblImages ( imageID INT UNSIGNED NOT NULL AUTO_INCREMENT, ... ); tblImag...

When to prefer Xampp over a complete installation of Linux, Apache, MySQL, PHP

In which cases, except development, would you prefer Xampp over a complete installation and configuration of Linux, Apache, MySQL, PHP. ...

How can I protect MySQL username and password from decompiling?

sadly Java Classes can be decompiled pretty well, how can I protect my database if I have to use the login data in the code? ...

How can I speed up this SQL query on MySQL 4.1?

I have a SQL query that takes a very long time to run on MySQL (it takes several minutes). The query is run against a table that has over 100 million rows, so I'm not surprised it's slow. In theory, though, it should be possible to speed it up as I really only want to get back the rows from the large table (let's call it A) that have a r...

What is the best way to synchronize data between MS Access and MySQL?

Hello, I have an access database on a windows machine, which I must import into mysql on a linux webserver. At the moment the access dabatbase table is exported as a text file, automatically copied with ftp, and then loaded into mysql. Is there a better way to do this, perhaps using an ODBC connection or something else? What is the b...

Is there a way to name columns in an INSERT statement?

When I do SELECT statements in PHP code I always select named columns, like: SELECT id, name from users; rather than using: SELECT * from users; This has the advantage of being more informative and readable, and also avoids problems later if new columns are added to the table. What I'm wondering is, is it possible to use the same ...

Call Multiple Stored Procedures with the Zend Framework

I'm using Zend Framework 1.7.2, MySQL and the MySQLi PDO adapter. I would like to call multiple stored procedures during a given action. I've found that on Windows there is a problem calling multiple stored procedures. If you try it you get the following error message: SQLSTATE[HY000]: General error: 2014 Cannot execute queries ...

Locking a MySQL database so only one person at once can run a query?

I am having a few issues when people are trying to access a MySQL database and they are trying to update tables with the same information. I have a webpage written using PHP. In this webpage is a query to check if certain data has been entered into the database. If the data hasn't, then i proceed to insert it. The trouble is that if two...