issue creating new db in wordpress mysql - php

I'm working on a WordPress theme that requires a db in mysql to store lots of data.
I'm currently working on an installation script to install the theme. I have written a function to create a new db in the same mysql that WordPress uses it self.
Every time i run the script, i get redirected to a page stating that WordPress is already installed. But I'm not trying to reinstall WordPress, just create a new db in the same sql that WordPress uses.
I have also written a function to create new tables, which works fine so I'm sure there is no issues with connection.
If this helps, here is the function:
function create_db_mysql(){
require ('con_db_var/db_4216841335655434.php');
$connect = mysql_connect($db_host,$db_user,$db_pswrd) or die(mysql_error());
mysql_query("CREATE DATABASE theme_db",$connect);
mysql_close($connect);
}
I fetch the db info from wp-config.php.
so in the db_4216841335655434.php:
require ('../../../wp-config.php');
$db_host = ( DB_HOST );
//etc etc....
when i call the create_db_mysql(), I get taken to a page telling me that WordPress is already installed and then followed by instructions on how to re-install.
any ideas?
thanks!

Database creation and table creation are different levels of privileges. Many shared hosting providers will not give PHP the access to create a database.
So you might need to use your hosting providers control panels to create the database.

Related

Wordpress still trying to connect to old database

I am Running wordpress on Ubuntu 18.04 with apache2 and PHP 7.2.24. I deleted the wordpress files and dropped the database to copy another wordpress site. I copied the other wordpress (Files and database) into a new database (new name, new user, new password), Then changed the wp-config.php file values to the (new name, new user, new password). Now when I try to open the site it still trying to connect to old databases as if I didn't change the wp-config.php file, I get this error
Can’t select database
We were able to connect to the database server (which means your username and password is okay) but >not able to select the v3GMwXpnRQjq database.
Are you sure it exists?
Does the user zJ6epncZUYcQ have permission to use the v3GMwXpnRQjq database?
On some systems the name of your database is prefixed with your username, so it would be like >username_v3GMwXpnRQjq. Could that be the problem?

Google-App-Engine[PHP]: Error trying to establish database connection

I am finding a problem with the cloudsql as database connection is not being established. I have followed the following site step-by-step https://googlecloudplatform.github.io/appengine-php-wordpress-starter-project/
However I seem to be finding problems after deploying the project to the appengine and accessing the wordpress installation page with URL: https://<PROJECT-ID>.appspot.com/wp-admin/install.php
The error shown is:
**Error establishing a database connection**
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress_db' );
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', '' );
Can someone please advise a suitable solution to this error, as I cannot get around it and even though I am able to deploy my project. Without a database connection I cannot install Wordpress on cloudsql accordingly.
I have solved this problem with a work around. Since I was following the instructions from the web page, I researched further on the contributors behind it, leading to the GitHub link:
https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/appengine/wordpress
This was updated as of 2015, and I was able to follow the step-by-step procedure from this URL. I found it necessary to install the GitHub shell commands and clone the project to desktop.
All I needed to do was update the app.yaml and wp-config.php as required and than create the instance on Cloud SQL, following the 'wordpress' procedure with a new database created as wordpress_db and a new root user with a blank password.

mysqldump-php not working with shared hosting companies database. No command line access or SUPER privilege(s)

Does anyone know if mysqldump-php can work with shared hosting? I can get it to work on my local computer (I can get mysqldump to work locally also) but I need a method to backup a database that's hosted with a popular webhosting company. The only method that they offer to their customers is to sign onto phpMyAdmin and download your .sql manually. daily. yourself. no automation allowed. I'm a newbie and I'm going nuts trying to find a solution.
mysqldump-php called for
namespace Ifsnop\Mysqldump;
use Exception;
use PDO;
use PDOException;
It didn't mention needing command line access or SUPER privilege(s).
Am I using incorrect settings?
Here's the link to the code that I'm using on Github.
https://github.com/ifsnop/mysqldump-php#dump-settings
Any help would be so appreciated!
I've had a look in the code of ifsnop, and it uses SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ before starting the transaction. Global settings are only allowed with the SUPER-privilege (which you don't have on a shared environment, with a good reason ;) ).
You can either:
If you have only MyISAM-tables, there is no need for a transaction, so it can be turned off in the config.
$dumpConfig = array(
'single-transaction' => false
);
$md = new Mysqldump($db, $user, $pass, $host, 'mysql', $dumpConfig);
or; Change that word GLOBAL into SESSION (thus modifying the downloaded code).

WebMatrix 3 not showing MySQL databases

I am new to WebMatrix and MySQL, and I need some assistance with an issue.
I'm trying to code with PHP and MySQL in WebMatrix 3. I am experimenting with scripts in a site file called "Starter PHP site". WebMatrix is not showing a database created with the $sql="CREATE DATABASE my_db"; script when I navigate to the "Databases" section in the program. This image shows what part of the program I'm talking about.
(source: orchardproject.net)
When I click the "Databases" button in the lower left corner of the UI, all that is shown in the left pane is a "Starter PHP site" folder icon (for creating a MySQL databse for my site from the WebMatrix UI) and an "Other Connections" icon -- but not the database created (my_db) after running the script above.
I know that the database exists...because when I run the script above again with some extras--
$con=mysqli_connect("localhost","xxxx","xxxxxxxx");
$sql="CREATE DATABASE my_db";
if (mysqli_query($con,$sql))
{
echo "Database my_db created successfully";
}
else
{
echo "Error creating database: " . mysqli_error($con);
}
--I get an error saying that "my_db" already exists. Why doesn't WebMatrix show my_db in the "Databases" section...after I've run the script to create the database?
What am I missing here?
Any advice is greatly appreciated.
If it's there you should see it as such:
Dumb question, but have you tried refreshing?
It seems that I have found some sort of solution. Apparently, WebMatrix 3 might not show MySQL databases created with PHP scripts automatically, but you can view databases created with scripts by creating a new MySQL database connection to the database of interest from the WebMatrix GUI.
Solution: Navigate to the "Databases" section.... Select "New," then..."MySQL Connection." Then, enter the database information.... You should now have a working database connection.
...sorry if this is one of those newbie mistakes. I should have tried this earlier, but one might think that, since one has to establish a database connection in the PHP code, WebMatrix would automatically connect to it. For me, that isn't the case.

Connect to online Magento from a localhost

Beside setting up a custom Magento API, is there a way to connect from a localhost webapp to an online Magento installation? More specifically, I'm looking for a setup that will allow me to write codes like
include('app/Mage.php'); // how does this work for online-offline connection??
$products = Mage::getModel('catalog/category')->load($category_id);
in a webapp running on localhost in our office.
If this is not plausible, do I need to connect to the Magento store DB directly from my application and basically write my own queries? I would certainly create a new user with read-only access for the DB, if this was the case.
No need to connect to the db the include will handle it:
require'app/Mage.php';
if (!Mage::isInstalled()) {
Mage::log("Application is not installed yet, please complete install wizard first.\n",null,'fiftyone_daemon.log');
exit;
}
Mage::app('default');
$products = Mage::getModel('catalog/category')->load($category_id);

Categories