CodeIgniter: Executing database script at the startup of application - php

I have just started using CodeIgniter for my PHP application. I need some help regarding database creation. Instead of creating database manually is it possible that when CI application in installed on any server then after starting the apache server, my application should execute some db script file to create DB structure if the DB is empty otherwise skip the DB creation. So every time when the apache server is started or restarted, my CI application should execute this script and check whether the database structure is up to date or not and create it if does not exist or not up to date.
This way I want to make sure that after first install or everytime the application runs the DB is created and ready to use.
Hope I have explained my requirement clearly. Please let me know if any kind of configuration will help me here.

Related

Accidentally uninstalled mysql on AWS EC2 with wordpress multisite. Need a little guidance

I have a wordpress multisite installation running on an AWS EC2 (t2.medium).
After messing around trying to get phpmyadmin installed on the server I accidentally deleted httpd,mysql-server etc. It broke everything.
Thankfully, I used a plugin called Snapshot from wpmu-dev and had everything backed up but now I'm running into some trouble and not entirely sure how to do this.
Current situation:
1. Created an instance snapshot through my aws dashboard.
2. Backed up everything from /var/www/html/ to my local drive.
3. Reinstalled mysql and httpd, started it, went through the steps provided here - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html - however, when setting up the database it states that wordpress-db and the user are already there and my old password still works yet wordpress isn't working?
So I'm not sure where to go from here, shall I just delete my instance and start again from scratch? Loading what I need back into the /var/www/html folder? Or is there a way that I can completely delete my database and then rebuild the tables with the snapshot and get back to where I started?
Thanks in advance for your help folks, really stuck here, have a website that's down!
If you are not sure what happened I would recommend you start from scratch.
Launch an EC2 instance and follow the steps on the guide you provided:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html
Download MySQL workbench and connect to the database (remember
modifying the security permissions temporarily
to be able to connect to the database from your computer) (https://dev.mysql.com/downloads/workbench/)
Restore the sql backup (if you have one, or create one if you don't) to restore the database to your new ec2 instance MySQL. You can do this following the Data import section: https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html
Make sure the configuration file is correct (url, database path, name, etc) (https://codex.wordpress.org/Editing_wp-config.php)
I would recommend to point your domain to your new ec2 instance only after it has been properly configured and tested.

While working on two laravel projects at the same time, laravel is trying to access the database of the last project that made a request

This is super weird, never come across it before. But basically I have a laravel app running ajax requests in the background while I work on a different laravel app. Whenever I try to refresh the app i'm working on, it gives me a db connection error because app2's tables don't exist on app1's database.
I've check the .env, they are configured differently, I've tried composer dump autoload, I've tried clearing cache. Not sure what's going on here, it may be apache settings I suppose?
Any help greatly appreciated.
There is one more database configuration file that is database.php which is located in config folder.So first u need to check this file and write your credential in your respective database.

Connection issues with LocalDB

I'm testing out a website I made in local environment, using Sql Server LocalDB as I said above. The site's done, now I wrote a php script that connects to the database and sends out some emails based on the database contents. I need this script to run automatically, so I've already set up a batch file in the Windows Task Scheduler to run automatically every hour. No problem in this. The issue is that sometimes (pretty often actually) the php scripts can't connect to the database. This seems to happen mostly when I recently "explored" my website, so my question is:
does LocalDB allow only one connection at a time?
If you have other ideas, please tell me. I need to finish testing ASAP.

$mysqli->insert_id not working with PHP on openSUSE

I'm in the process of moving a PHP application from an Ubuntu server to an AWS openSUSE instance.
The application does not work on the openSUSE box. The API fails for any call that has $mysqli->insert_id. Calls using $mysqli do work.
From reading around I have noted that this usually fails because of auto_increment not being implemented on the Database column. I migrated the MySQL database across from the Ubuntu hosted app. The table schema seems to be the same.
I have also looked at the server configuration files php.ini etc. and the MYSQLi extensions seem to be configured correctly.
It is for this reason I think it is a PHP related problem. Any help would be greatly appreciated.
EDIT : To provide more information as requested.
The general structure of each API call that fails is.
The iOS sends a POST to the API
The API (built in PHP) inserts the information into a Table which has a Primary Key that auto-increments.
The API then uses $case_id = $mysqli->insert_id;, obtain the value of this primary key.
This value is returned to the iOS app.
Important - $case_id is being returned as 0.
To troubleshoot an issue like this I would start by isolating where the problem is occurring. Is the schema wrong? If you log into the MySQL server using the MySQL shell and you attempt to manually insert a record, with a NULL for the auto-incremented (primary key?) column does the new record appear properly? If you query using the same underlying SQL statement that's being generated and passed to the server from your PHP/mysqli component does it return the proper row(s)?
If it works using the MySQL shell on the DB server then what if you try the same from the API server? Is it a permissions/ACL or networking issue? If the it works from the MySQL shell on both the DB server and the API (web?) server then does it work from your PHP code? Perhaps you can refactor your PHP to allow you to run tests/diagnostics from the command line (rather than attempting to initiate a transaction through the additional web/UI layers). (This is generally a good idea when writing your web applications anyway). Perhaps you can separate the web/form/ReST handling (view) from the code which passes data back into the DB (the model). Thus you isolate the controller code from the rest and can re-use it for diagnostics and for monitoring.
If you can't get it working even from the DB server's only MySQL shell prompt then you probably have a problem in the schema. Go back to the working DB server and perform a schema dump as described here: http://forums.mysql.com/read.php?35,128003,128105
Then restore that. It should then be a completely empty database with your working schema intact. If that doesn't work then it suggests you have some issues even lower (MySQL version and modules perhaps, missing some storage backends?)

Creating procedures, using putty.exe

I am doing an mysql php application and I need to create a procedure to make my foreign keys work fine and also to create a calendar for report purposes. However, I have been trying to create the procedures and it does not works in putty.exe which is the only software available to do my application. I researched and I did not find anything related to this. Can anyone advise if I will need extra files for putty or the way to do it?
You need to use the mysql client to run commands against mysql. In the putty command line just run:
mysql
You will most likely need to add parameters to the command, like the user and the password needed to connect. Check the MySQL manual for details.
To run the script file that contains your procedure, first you have to upload the file to the server and then run it with
mysql < script.sql

Categories