Problem with ColdFusion communicating with MySQL database - mysql

I have been working to migrate a non-profit website from a local server (running Windows XP) to a GoDaddy hosting account (running Linux). Most of the pages are written in ColdFusion. Things have gone smoothly, up until this point. There is a flash form within the site (see this page: http://www.preservenet.cornell.edu/employ/submitjob.cfm) which, when completed, takes the visitor to this page: submitjobaction.cfm . I'm not quite sure what to make of this error, since I copied exactly what had been in the old MySQL database, and the .cfm files are exactly as they had been when they worked on the old server. Am I missing something?
Below is the code from the database that the error seems to be referring to. When I change "Positionlat" to some default value in the database as it suggests in the error, it says that another field needs a default value, and it's a neverending chain of errors as I try to correct it.
This is probably a stupid error that I'm missing, but I've been working at it for days and can't find what I'm missing. I would really appreciate any help.
Thanks!
-Greg
DROP TABLE IF EXISTS `employopp`;
CREATE TABLE `employopp` (
`POSTID` int(10) NOT NULL auto_increment,
`USERID` varchar(10) collate latin1_general_ci default NULL,
`STATUS` varchar(10) collate latin1_general_ci NOT NULL default 'ACTIVE',
`TYPE` varchar(50) collate latin1_general_ci default 'professional',
`JOBTITLE` varchar(70) collate latin1_general_ci default NULL,
`NUMBER` varchar(30) collate latin1_general_ci default NULL,
`SALARY` varchar(40) collate latin1_general_ci default NULL,
`ORGNAME` varchar(70) collate latin1_general_ci default NULL,
`DEPTNAME` varchar(70) collate latin1_general_ci default NULL,
`ORGDETAILS` mediumtext character set utf8 collate utf8_unicode_ci,
`ORGWEBSITE` varchar(200) collate latin1_general_ci default NULL,
`ADDRESS` varchar(60) collate latin1_general_ci default 'none given',
`ADDRESS2` varchar(60) collate latin1_general_ci default NULL,
`CITY` varchar(30) collate latin1_general_ci default NULL,
`STATE` varchar(30) collate latin1_general_ci default NULL,
`COUNTRY` varchar(3) collate latin1_general_ci default 'USA',
`POSTALCODE` varchar(10) collate latin1_general_ci default NULL,
`EMAIL` varchar(75) collate latin1_general_ci default NULL,
`NOMAIL` varchar(5) collate latin1_general_ci default NULL,
`PHONE` varchar(20) collate latin1_general_ci default NULL,
`FAX` varchar(20) collate latin1_general_ci default NULL,
`WEBSITE` varchar(200) collate latin1_general_ci default NULL,
`POSTDATE` varchar(10) collate latin1_general_ci default NULL,
`POSTUNTIL` varchar(20) collate latin1_general_ci default 'select date',
`POSTUNTILFILLED` varchar(20) collate latin1_general_ci NOT NULL default 'until filled',
`texteHTML` mediumtext character set utf8 collate utf8_unicode_ci,
`HOWTOAPPLY` mediumtext character set utf8 collate utf8_unicode_ci,
`CONFIRSTNM` varchar(30) collate latin1_general_ci default NULL,
`CONLASTNM` varchar(60) collate latin1_general_ci default NULL,
`POSITIONCITY` varchar(30) collate latin1_general_ci default NULL,
`POSITIONSTATE` varchar(30) collate latin1_general_ci default NULL,
`POSITIONCOUNTRY` varchar(3) collate latin1_general_ci default 'USA',
`POSITIONLAT` varchar(50) collate latin1_general_ci NOT NULL,
`POSITIONLNG` varchar(50) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`POSTID`)
) ENGINE=MyISAM AUTO_INCREMENT=2007 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
UPDATE:
Where I think the "submitjobaction.cfm" page communicates with the database:
<CFINSERT DATASOURCE="mysqlcf_preservenet" TABLENAME="employopp" FORMFIELDS=" TYPE, JOBTITLE, NUMBER, SALARY, ORGNAME, DEPTNAME, ORGDETAILS, ORGWEBSITE, ADDRESS, ADDRESS2, CITY, STATE, COUNTRY, POSTALCODE, EMAIL, NOMAIL, PHONE, FAX, WEBSITE, POSTDATE, POSTUNTIL, texteHTML, HOWTOAPPLY, CONFIRSTNM, CONLASTNM, POSITIONCITY, POSITIONSTATE, POSITIONCOUNTRY">
<CFINSERT DATASOURCE="mysqlcf_preservenet" TABLENAME="user" FORMFIELDS=" ORGNAME, WEBSITE, ADDRESS, ADDRESS2, CITY, STATE, COUNTRY, POSTALCODE, EMAIL, PHONE, FAX, CONFIRSTNM, CONLASTNM" >

I use none of mysql, cfform or cfinsert so ymmv with this answer, but it seems like the problem is in the database configuration.
This blog post from 2007 suggests changing an ini setting for sql-mode. You'll need to talk to your host to check the current value and try to have it changed.
It looks like the form is sending zero-length values for unanswered fields and the database is rejecting those values.
Another approach is to replace the cfinsert with a normal cfquery - this will give you more flexibility with how you supply 'empty' values.

I get the following error message:
Error Executing Database Query.
Field 'CONFIRSTNM' doesn't have a default value
Resources:
...
What seems to happen here is that some form field (named CONFIRSTNM - I assume that's the Contact Firstname) is empty in the POST and the database doesn't have a default value set. Because your cf code is using CFINSERT you don't actually write the SQL code yourself but CF is supposed to do it for you. Hard to debug from the distance, but I think what you should do is to make sure the database was 1:1 migrated from the old environment to the new environment. Not sure how the migration was done, but it might have lost some information along the way.
Another suggestion for good coding practice is to rewrite CFINSERT with a CFQUERY tag and write the SQL statement yourself. Also make sure you use CFQUERYPARAM for all incoming parameters.

Related

I need to optimize a large data table in a mysql database

I have a table in a mysql DB with about 6 mil rows of data. Structure below. Most of my queries are searching for specific "customer" fields and display a value for each customer according to the value in column "value". The query searches the whole Table to match those customers specified in the query. This table started rather small but now it's gotten too big and my queries are taking quite some time to retrieve results. My questions is the following: If i create a separate table with just the customer field, along with an index, will that make my customer queries faster?
TABLE `data` (
`id` bigint(20) UNSIGNED NOT NULL,
`entry_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`date` date DEFAULT NULL,
`media_name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`media_type` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`rate` decimal(8,2) DEFAULT NUCREATELL,
`value` decimal(8,2) DEFAULT NULL,
`page` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`sector` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`category` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`customer` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`product` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`image_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`city` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`supplier` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`time` time DEFAULT NULL,
`duration` time DEFAULT NULL,
`promoted_on` datetime NOT NULL,
`hasimage` tinyint(4) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
You want an index.
If you are searching for customers using in or = (the most common methods), then you can use a standard index on customer.
If you have more complex searches -- say using like with a leading wildcard -- then this does not work. A full text index might help. Or it might not, depending on the nature of the query and the data.
The "separate table" you're thinking about should be an index on your main table.
CREATE INDEX index_name
ON data(customer,value);
This will speed up the queries, and even prevent access to the table itself, at the cost of slightly slower INSERT and UPDATE operations.

Yii2 encrypt and Mysql

I hope someone can help me with this.
I am saving a personal data into MYSQL by encrypting using Yii2 encrypt/decrypt function, testing without saving the content into the DB works.
However saving the content into the DB and retrieving it back, seems something goes wrong because I am not able to decrypt it.
My MYSQL scheme is this
CREATE TABLE IF NOT EXISTS `customer` (
`customer_id` int(11) NOT NULL,
`customerHash` varchar(32) COLLATE utf8_bin DEFAULT NULL,
`customerDate` date DEFAULT NULL,
`customerTime` time DEFAULT NULL,
`customerUpdated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`customerEmail` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`customerPassword` varchar(45) COLLATE utf8_bin DEFAULT NULL,
`customerToken` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`customerAddress` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`customerPhone` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`customerPostcode` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`customerName` blob,
`customerSurname` varchar(255) COLLATE utf8_bin DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
Yii code
Encrypt
$request=Yii::$app->request;
$hash=Yii::$app->getSecurity()->generateRandomString();
$model->customerHash=$hash;
$model->customerName=Yii::$app->getSecurity()->encryptByKey($request->post('customerName'), $hash);
Decrypt
<? echo"Decode : ".Yii::$app->getSecurity()->decryptByKey($model->customerName, $model->customerHash);?>
Any help welcome.
Thanks

Not inserting Turkish characters in SQL table. Displays 'xxx??xxx' when selected

I am trying to add Turkish names on my table but then when displayed it gives me ? instead of any of them. Any help what I am missing here? This is my table:
CREATE TABLE IF NOT EXISTS `offerings` (
`dep` varchar(5) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`grade` varchar(4) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`section` varchar(3) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`name` varchar(100) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`teacher` varchar(50) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`quota` varchar(2) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`lec1` varchar(35) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`lec2` varchar(35) CHARACTER SET utf16 COLLATE utf16_turkish_ci DEFAULT NULL,
`lec3` varchar(35) DEFAULT NULL,
`lec4` varchar(35) DEFAULT NULL,
`lec5` varchar(35) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf16;
As suggested from the answer I choose here is the solution to the problem for whoever googles this topic. Special thanks to all who contributed in the solution of my problem.
CREATE TABLE IF NOT EXISTS `offerings` (
`dep` varchar(5) NOT NULL,
`grade` varchar(4) COLLATE utf8_unicode_ci NOT NULL,
`section` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`teacher` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`quota` varchar(2) COLLATE utf8_unicode_ci,
`lec1` varchar(35) DEFAULT NULL,
`lec2` varchar(35) DEFAULT NULL,
`lec3` varchar(35) DEFAULT NULL,
`lec4` varchar(35) DEFAULT NULL,
`lec5` varchar(35) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(Beginnings of an answer...)
Please don't use utf16; there is virtually no reason for such in a MySQL table.
So, assuming you switch to utf8, let's see if we can get rid of the ? problems.
utf8 needs to be established in about 4 places.
The column(s) in the database -- Use SHOW CREATE TABLE to verify that they are explicitly set to utf8, or defaulted from the table definition. (It is not enough to change the database default.)
The connection between the client and the server. See SET NAMES utf8.
The bytes you have. (This is probably the case.)
If you are displaying the text in a web page, check the <meta> tag.
What probably happened:
you had utf8-encoded data (good)
SET NAMES latin1 was in effect (default, but wrong)
the column was declared CHARACTER SET latin1 (default, but wrong)
Since the CHARACTER SET disagrees with what you have shown, the problem is possibly more complex. Please provide
SELECT col, HEX(col) FROM tbl WHERE ...
for some simple cell with Turkish characters. With this, I may be able to figure out what happened.
Also, Reference notes on encodings.
VARCHARs are character strings, while NVARCHARS are Unicode character strings. NVARCHARS require more bits per character to store, but have a greater range. Try updating your data types. This should fix your problem.
EDIT This answer is wrong. The OP clearly asked for a MySQL solution, but the above applies only to SQL Server.

Zero timestamp value not accepted when using MySQL .NET connector

We have a C# tool to create a (MySQL) schema on a developer machine based on the (MySQL) schema used in production. This tool runs SHOW CREATE TABLE queries on the source connection, grab the resulting table creation scripts and run them locally.
I'm using MySQL 5.7.7 Community Server locally.
One of the creation script looks like this:
CREATE TABLE `agency` (
`id` int(11) unsigned NOT NULL,
`name` varchar(512) COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(512) CHARACTER SET ascii NOT NULL,
`location_path` varchar(10) CHARACTER SET ascii NOT NULL,
`email_pattern` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`generic_email` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`address` text COLLATE utf8_unicode_ci,
`zip_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`city` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`region` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`country` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`phone` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`inserted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
When I run this query in MySQL Workbench, the table is successfully created.
However, when this query is executed on the destination connection by our C# tool, the following error occurs: Failure: Invalid default value for 'inserted_at'.
My MySQL Workbench is configured with the following SQL_MODE: TRADITIONAL,ALLOW_INVALID_DATES.
My MySQL Server instance is configured with the following sql-mode: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Here are the connection strings used by our C# tool:
Local connection string:
Server=localhost;Database=XXX;Uid=XXX;Pwd=XXX;AllowZeroDateTime=true
Source connection string:
Server=X.X.X.X;Database=XXX;Uid=XXX;Pwd=XXX;Use Compression=true;AllowZeroDateTime=true
Any idea appreciated!
It looks like removing STRICT_TRANS_TABLES from sql-mode in my.ini fixes the problem.
Is this the correct fix?

FULLTEXT SEARCH not working mysql

So i get an error when i try and use
SELECT views, keywords, title, url, thumbnail,
MATCH(keywords,title) AGAINST ('%$search_value%') AS relevance
FROM straight
WHERE MATCH (keywords,title) AGAINST ('%$search_value%')
ORDER BY relevance DESC
This is due to me not having FULLtext search enabled, but i cant seem to enable it. when i run the sql below:
ALTER TABLE straight ADD FULLTEXT(keywords, title)
i get this response:
MySQL returned an empty result set (i.e. zero rows). (Query took 3.8022 sec)
Then when trying to run the first query again i get the failed
#1191 - Can't find FULLTEXT index matching the column list
I can't tell why it's not registering. Any help would be great.
Thanks!
Edit:
My tabel:
CREATE TABLE `straight` (
 `url` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `title` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `keywords` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `production` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `categories` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `views` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `likes` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `length` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
 `thumbnail` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
 `date` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL,
 UNIQUE KEY `url` (`url`),
 FULLTEXT KEY `url_2` (`url`,`title`,`keywords`,`production`,
`categories`,`views`,`likes`,`length`,`thumbnail`,`date`
), ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
You need a FULLTEXT index that matches, exactly, the columns upon which you want to search. The FULLTEXT index you have has more columns than you need.
Try adding the one you mentioned.
ALTER TABLE straight ADD FULLTEXT(keywords, title)
Then look at the table definition and make sure it's there.