php posting to DB mysql increments not working - php

So I'm currently having a problem with my DB's auto increments. ( NOTE THIS WORKED ON MY OLD HOST I'VE SINCE THEN CHANGED SERVERS AND NOW HOSTING ON A UBUNTU SERVER ). Which I'm not really sure if that makes a difference.
But here is the data that gets "INSERTED" into the DB or what should be.
mysql_query("INSERT INTO table_fruits VALUES ('', '$description', '$keywords', '$fruits')");
so the first '' should be the ID that auto increments but it doesn't.
I've tried removing the '' and leaving just the ,
I've tried totally removing the '',
Only thing I've tried and succeeded is changing it to '0', for a strange reason that worked but there are a lot of files and pages to check if that worked correctly and to edit.
Surly that's not an efficient way to resolve this anyway. I don't currently have the old hosting anymore so I can't even check on a PHP version if that was causing the problems.
Are there any query's I can run to resolve this dramatic stressful problem that's been driving me batty for hours now? I appreciate any help.

Actually you can change from column settings as autoincrement. But at this point, I have encountered different problems with different versions of MySQL. So if you want to achieve the direct result in practice, export the whole table. Define autoincrement over SQL code. Run the new code.
Note: Make sure you get a backup!

Related

Insert query works directly in MySQL, not via Code Igniter it passes an empty value

In my Code Igniter (PHP) application I insert multiple rows using the query below:
INSERT INTO attribute_data (attribute_ID,product_ID,attribute_value) VALUES (2,3,123),(2,3,543)
The column named 'attribute_value' is set to 0 for both rows.
However, when I paste the query directly into phpMyAdmin it sets the column 'attribute_value' with the given numbers (123 and 543 in my example). So, my guess is that nothing is wrong with the query. But please correct me.
Probably not very helpful, but here is my Code Igniter code:
$sql = "INSERT INTO attribute_data (attribute_ID,product_ID,attribute_value) VALUES (2,3,123),(2,3,534)";
$this->db->query($sql);
Some info on what I've been looking at:
I've already tried using quotes although it's an integer.
The 'attribute_value' column is not a primary key
UPDATE
I've enabled profiling. The query is the same in the profiling output.
UPDATE 2
I tried using the insert_batch() method with the same result. Records are still being added with 0 instead of the given value.
$this->db->insert_batch('attribute_data',$insert_data);
Thanks for all your help. The acknowledgement of my code and the query being OK was enough for me to start thinking about caching.
I checked out caching of MySQL first but this is taken care of out of the box. The Code Igniter caching was causing the problem here. Not the end solution of course, but below method helped me out a lot.
$this->db->cache_delete_all();
Once I delete the cache before inserting data, the correct values were inserted. So,the column attribute_value was in cache somehow. Now my quest continues to make it work with Code Igniter caching turned on.
Thanks again, you rock!
The above mentioned code is working fine. I think you have a database connection issue.
Change the environment to development mode in index.php file
index.php file is located in root folder of your project. Change the text production to environment.
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : '`development`');

PHP MySQLi autocommit went off without warning?

Here's a strange case that has never happened to me before, I've been coding with mysqli and php for about 2 years now, very basic stuff, prepared statements, query executes, etc, started with WAMP, then moved to ubuntu, tried LAMP, didn't like it, went on investigating a proper testing enviroment, and I found PuPHPet, which was perfect, have been working with it a few months, and everything is going great.
Never in all this time I had to worry about opening, closing or commiting connections, like I do in JAVA, I read somewhere that php handles connections, it opens and closes them when the scripts runs. I've never really pay much attention, which I should have, I found this very useful post PHP + MySQL transactions examples, which I will start using from now on.
But the reason I'm posting here, is because all of a sudden autocommit is off. I opened my usual puphpet project, tried inserting some new entries, and they did not get inserted. So, I made some test in workbench, inserted some entries manually, they got inserted, but my AI index had incremented, meaning that my app did insert something, or at least it tried, or something happened because the AI counter had increased. Got some help from a couple of DBA and we got to the conclusion that it is the autocommit.
Using this piece of code:
$res = mysqli_query($mysqli, "SELECT ##autocommit");
$row = mysqli_fetch_row($row);
printf("Autocommit: %s\n", $row[0]);
It prints "Autocommit: 0", so it is off, but I didn't change anything, even in production enviroment autocommit is on, or at least my inserts stay there, but I don't know why it changed in my test enviroment, so I'm wondering what could have happened? Anybody got any ideas?

ORA-03135 on Select Statement

This is a very recurring issue with some Oracle's Database users and I have read and tried different approaches withous success.
I am experiencing ORA-03135 error during a SELECT statement. It happens only on specific records of one table. The table has a field defined as varchar(4000) and I discovered that the error occurs when I try to read a record with a big string at the field I told before (about 2000 characters or more).
After some reading I tried to set SQLNET.EXPIRE_TIME, SQLNET.INBOUND_CONNECT_TIMEOUT,
SQLNET.SEND_TIMEOUT and SQLNET.RECV_TIMEOUT without success.
I don't think it is a timeout problem because if I try the same query on a client like Sqlplus it works ad i get the result instantly.
There is no firewall on the network and no alerts/logs are generated on server side when the error occurs. There is also no profile limitation.
I am using an Oracle 11.2 database running on Oracle Linux and PHP OCI8 to retrieve the data.
Is there any other place I could look for?
Thanks in advance!
Ok, just solved it...
I was wrong. It seems the error occurs on strings with some kind of crap at the end of it, not only big ones. Removing the last character solves the problem.
I will do some further investigation and try to discover exactly what is going on.
Edit 1:
100% sure now, the error occurs when the last string is an escape character "\n". Pretty funny, huh?

Mystery ghost MySQL insert query

My MySQL db has inserted rows which should not be there, in a particular there is data in a column not generally used. I thought this would make it easy to find which PHP script was inserting the rows but i have searchd all insert querys for the entire site and cannot find which php script is running the insert query.
Its also very hard to replicate as this particular table has many crons updating it.
Can anyone please try point me in the right direction of how I might go about debugging this. Is there a stack track I can use to determine the originating php script. Because it hard to replicate and I've spend two days searching for the code causing the inserts Im open to suggestions.
Im normally quite good at debugging but this bug is like a ghost.
The only thing I can think of, if you have looked at all your code including in all your old cron scripts, is to put an insert trigger on that table, and use it to find out what time of day your extra rows get inserted.
Nasty problem!
This might be a horrible idea depending on your error reporting settings and what type of environment you are debugging in, but if you are in a position to have some errors thrown I'd remove write permissions for the column in question and wait to see what script throws the error. If you are lucky log/report for the error will be written to include a script name and line.

Optimizing and compressing mysql db with drupal

I have developed a news website in a local language(utf-8) which server average 28k users a day. The site has recently started to show much errors and slow down. I got a call from the host saying that the db is using almost 150GB of space. I believe its way too much for the db and think there something critically wrong however i cannot understand what it could be. The site is in Drupal and the db is Mysql(innoDb). Can any one give directions as to what i should do.
UPDATE: Seems like innoDb dump is using the space. What can be done about it? Whats the standard procedure to deal with this issue.
The question does not have enough info for a specific answer, maybe your code is writing the same data to the DB multiple times, maybe you are logging to the table and the logs have become very big, maybe somebody managed to get access to your site/DB and is misusing it.
You need to login to your database and check which table is taking the most space. Use SHOW TABLE STATUS (link) which will tell you the size of each table. Then manually check the data in the table to figure out what is wrong.

Categories