SQLite, PDO, and PHP: New inserts not being saved - php

I have a few PHP (version 5.1.6) scripts and an sqlite3 database. For a while, everything was working fine, including inserts, updates, selects, and deletes.
Now:
Select statements still work fine
Inserts, deletes, and updates all fail without an error that I can see. A -journal file is created in the same directory as the database, but it later disappears. The sqlite file remains unmodified.
I can't really figure out what, if anything, has changed. Permissions are the same. I've been able to open and save the database in another program, and replaced it with that version, but I still have the same problem. The scripts originally were all in autocommit mode; using explicit commits does not fix the problem either.
If I replace the database file with an older backup, everything works just fine.
I'd appreciate any ideas for troubleshooting. Thank you!

Take a closer look at the permissions. Make sure PHP/Apache has read/write capability and owns the folder and the SQLite database file.

Related

Moving Xamp after formatting my computer and finding all my Databases empty

I recently had to format my computer but I made sure I backed-up all my files before. I am developing lots of local sites using Xamp on my Windows 7 machine.
When I tried to move the files back onto the same drive (c:) and then looked at PHPMYADMIN the tables where there but all empty.
I have all the xamp files including the .frm files but the phpmyadmin shows the DB's but they are all empty i.e showing no tables inside.
Really hope someone can help as I have potentially lost a LOT of work. Thanks in advance.
When you said "I made sure I backed up all my files" -- which files are you talking about? There are the MySQL data files, the XAMPP program files, and then any exported .sql files you may have backed up. The best way to create a backup is to "dump" an SQL file from the database ("Export" from within phpMyAdmin, though I generally use the mysqldump command-line tool). If you didn't do that but still have the MySQL data directory, the links provided by Peter Michael will guide you (although relying on the MySQL data directory isn't generally a good backup means, because of various inconsistencies or loss that can occur with your data; whether it works at all also depends on your table type). I don't know where those data files are stored when using XAMPP and a cursory Google search gives a couple of different options, so good luck.

Why does my MySQL database tables only exist on my Workbench?

I am developing my first php-MySQL system, but have a minimum of database experience. I have successfully created a schema with aproximately 10 tables, and the testings have so far worked fine.
My problems started when i created a dump of the database, as copy for my laptop, so I could continue to test new web pages and new queries even when I am not at home, and still use a localhosted database.
I have successfully imported the dump, and created the schema in my workbench, and it is visible from the command-line prompt "show databases".
However, both my web application, and the command-line prompts are unable to locate the underlying tables. THe problem is at least not directly in my php-code, as it works perfectly on another computer, with another, but assumably identical localhosted database. I have researched the matter online for what feels like a decade, but without any relevant results.
Command-line prompts are able to find tables from every other schema, like the sakila examples. I have tried to compare the two's settings, but they all seem to be identical, for instance they are both InnoDB.
I realise that I am not giving enough information for a direct solution here, but I would greatly appreciate if anyone could hguide me to finding the right questions to ask, so I can solve this matter, and get on with my php-learning.
(SOLVED)
I discovered that the list of open tables had references to an additional Schema. I thereafter realised that I had installed the XAMPP bundle server before I installed MySQL Workbench. In other words, i already had an existing database, with all of the regular examples included in another instance, which were running on port 3306. It also happpened to have an identical, but empty scheme, of the name that I tried to access.
My newly added SQL installation was ported to 3307, and so I am now able to access it. THis issue was just one of several issues I have been able to work around, but they have all been caused by the same mistake. Thanks everyone for trying to help.

Old Mysql to new Mysql?

I was learning some web design about 18+ months ago and got caught up on some other things and had to stop for a while. I'm getting back into web design again. I used xampp back then and using xampp now also. I found my old xampp zip of the entire folder. I extracted it thinking I might get lucky and get my databases back from mysql. I go into the xampp\mysql\data and I copied all the folders with the databases I wanted to put into the new mysql. I loaded up phpmyadmin and the databases are there but they are all empty.
The main database I want to save has these files inside of it...
db.opt
pcms_categories.frm
pcms_meta.frm
pcms_posts.frm
pcms_users.frm
so I see the table files there but mysql isn't loading them. I assume maybe it's an older version and it won't read these files because they are obsolete. I'm not sure. After transferring the files I stopped mysql and reloaded it so just wanted to mention that.
It's been so long ago that it doesn't exactly matter if I can recover this data. I was working on a blog though would be cool to get that back and finish what I started.
try to dump it to .sql perhaps?
in other word, export/import.
First, I'd check for permission issues. MySQL usually requires special permissions on its datafiles. Check to see if MySQL has created its own user/group. Next, I'd try to find out what version of MySQL you previously had, create an installation of said version, and use it to dump the datafiles to SQL.

Using PDO to write to SQLite database

I am trying to implement a simple database using PHP & sqlite on my Linux/Apache server.
I can read from it quite readily, but I cannot perform any UPDATE, DELETE or INSERT actions. The Fatal Error I get is:
General error: 5 database is locked
As a simple example:
$pdo=new PDO('sqlite:test.sqlite');
$pdo->exec("INSERT INTO menus(id,name,description) VALUES(6,'test','this is a test')");
This waits for a long time (about a minute), and then reports the above error.
I have read a lot of suggestions, many of which suggest that the database or its containing folder should be writable. They are. (Or were. I made them world writable for testing, and restored more reasonable permissions when that failed.)
I have no trouble writing to the database using other techniques such as the sqlite3 command in Linux and the SQLite manager addon in Firefox.
I would welcome any comments on how to make this work.
Please, try to give the database file a 777 permission and try again. I suspect it has something to do with permissions because you are able to modify the database using sqlite3 program.
If it fails, then try to see the answers to this question.

Adding a script to index.php

Dear stackflower users,
A few days ago there was a power outage and my mysql database was lost... (I did have a one month old backup)
So I started looking for a program that makes backups of my mysql database automatically.
I found a script that does exactly this, its called phpMyBackupPro
According to the readme I had to add:
require_once("phpMyBackupPro/schedule_backup.php");
To a page that gets loaded frequently (for example index.php)
So I tried adding this to my index.php page of joomla and clearing my joomla and browser cache.
However the backup files are not being created when I load the index.php, when I run the script manually they are however.
So I started looking for some addons that could load php files in joomla, but they either didn't work or they where not compatible with joomla 1.7.
is their anyone who knows how to get this script to work, or knows a better way of automatically backing up mysql databases on windows?
calling this script from the index.php is bad coding practice. God knows what does this script do!
I recommend Akeeba Backup, I used it with small and large Joomla installations and it works like charm.
What I recommend more is to have periodic full account backup (e.x. cpanel), these backups holds more info (cron jobs, emails, ...) and are easier and faster to restore (if you have sufficient privilege of course).
EDIT: You don't have to have cpanel to make account backups. You can use shell scripts like this or that and use cron job to activate them.
I would avoid trying to what you mentioned and instead use a Joomla specific extension such as this:
http://extensions.joomla.org/extensions/access-a-security/site-security/backup/15682?qh=YToxOntpOjA7czoxMDoibGF6eWJhY2t1cCI7fQ%3D%3D
I have used this for years and it has saved my ass on multiple occasions so happily recommend it!
Having said that if you're dead set on what you've mentioned simply add it to the BOTTOM of your template file located: templates/your_templates/index.php
Hope this helps,
Andy
I made a solution for windows uswers:
I made a bat file script:
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --result-file=E:\mysql\backup.sql "-uroot" "-password" --databases joomla server phpbb
This is an example where you replace the text password with your own password and root with the username(in most cases this is root) the database names are joomla, server and phpbb.
This program runs every 1 hour be using the task schedule in windows.

Categories