Can not connect to MySQL with CodeIgniter. Possible DNS issue? - mysql

I am running a dev LAMP with Codeigniter. However, when I try to load the page, the database can not connect(the database is actually on another server) and I get this error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
My database.php is this:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'myhost.com';
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'mytable';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
If I change the 'pconnect' and/or 'db_debug' to false, I get the same error or it just doesn't work. I know the database is up and running correctly because others are able to connect and use it.
However, if I put the IP address of the host into the database.php file, it works.
I tried flushing the DNS and even changed to Google's DNS servers to no avail.
The result of a simple mysql_connect is:
A PHP Error was encountered
Severity: Warning
Message: mysql_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
Filename: config/database.php
Line Number: 67
A PHP Error was encountered
Severity: Warning
Message: mysql_connect(): [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (trying to connect via tcp://myhost.com:3306)
Filename: config/database.php
Line Number: 67
A PHP Error was encountered
Severity: Warning
Message: mysql_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
Filename: config/database.php
Line Number: 67
Could not connect: php_network_getaddresses: getaddrinfo failed: Name or service not known

Try change this
$db['default']['db_debug'] = TRUE;
to this:
$db['default']['db_debug'] = FALSE;

Ensure that the domain name is registered to the correct I.P. address and your host has the record of this exact address. Try placing a static HTML file on the website, all you need is something that displays maybe the text "Hello World" to ensure that you are able to access the website via the domain name.
Ensure that you have inserted the domain name correctly in the script and that you can log in to PHPMyAdmin (or whatever you use) with the required credentials via copy and paste (without leading and trailing whitespace, be careful of that).
If it is a problem with the table name, it should say so. As for the rest of the settings, I am not familiar with any of them, but what I have outlined here should see your database working.
Good luck.

Related

Fatal mySQL error while trying to access DVWA

I am trying to setup DVWA and I did all the steps according to this video (https://www.youtube.com/watch?v=cak2lQvBRAo) till renaming the config file to config.nic.php and changing the password field to blank.
Something like this-
$_DVWA[ 'db_server' ] = '127.0.0.1';
$_DVWA[ 'db_database' ] = 'dvwa';
$_DVWA[ 'db_user' ] = 'dvwa';
$_DVWA[ 'db_password' ] = '';
$_DVWA[ 'db_port'] = '3306';
I get the error on this page (http://127.0.0.1/login.php)-
Fatal error: Uncaught mysqli_sql_exception: Unknown database 'dvwa' in C:\xampp\htdocs\dvwa\includes\dvwaPage.inc.php:499
Stack trace:
#0 C:\xampp\htdocs\dvwa\includes\dvwaPage.inc.php(499): mysqli_query(Object(mysqli), 'USE dvwa')
#1 C:\xampp\htdocs\login.php(8): dvwaDatabaseConnect()
#2 {main}
thrown in C:\xampp\htdocs\dvwa\includes\dvwaPage.inc.php on line 499
Can't even access the DVWA setup. I am using XAMPP and the Apache2 (ports 80, 443) and mySQL (port 3306) are running fine. Please help!
Got the answer for you.
Try localhost/dvwa/setup.php on browser
Then click on create or reset database and it should get to login page
Remember user name and password must be same as what you configured in config.php
Good luck

SMTP configuration on Plesk Server (Centos)

I'm trying to make code to send a simple mail via SMTP, I read that I must use the class phpmailer and also install pear engine on the server root, I downloaded some different files to authenticate the SMTP but always requires more files that I don't have or cant be charged. Actually, the PHP errors display this:
Warning: require_once(): open_basedir restriction in effect. File(/opt/plesk/php/7.1/share/pear/PEAR.php) is not within the allowed path(s): (/var/www/vhosts/necotec.es/:/tmp/) in /var/www/vhosts/necotec.es/httpdocs/prueba_smtp/Mail.php on line 48
Warning: require_once(/opt/plesk/php/7.1/share/pear/PEAR.php): failed to open stream: Operation not permitted in /var/www/vhosts/necotec.es/httpdocs/prueba_smtp/Mail.php on line 48
Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:/opt/plesk/php/7.1/share/pear') in /var/www/vhosts/necotec.es/httpdocs/prueba_smtp/Mail.php on line 48
I dont know if cant be found or is a permision problem the files by default takes 644 permisions in this server. Any clue would be helpfull thanks.
open_basedir restriction in effect
error means that some files or scripts are located out of allowed directory.
In your case this file is /opt/plesk/php/7.1/share/pear/PEAR.php.
In Plesk you can disable open_basedir(not secure): Domains > example.com > PHP Settings and set open_basedir to none.
Another way(more secure) is to set open_basedir as {WEBSPACEROOT}{/}{:}{TMP}{/}:/opt/plesk/php/7.1
I was able to configure PHPMailer on my test server(Plesk 17.5-17.8) using steps:
Logged in to the server using SSH
Went to domain Document root directory: # cd /var/www/vhosts/example.com/httpdocs/
Run the command taken from github: # composer require phpmailer/phpmailer
As a result "vendor" folder appeared in "httpdocs" folder.
Created a testmail.php file based on 0-send-email-plesk.php:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2; # 0 off, 1 client, 2 client y server
$mail->CharSet = 'UTF-8';
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPSecure = 'tls'; # SSL is deprecated
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'Plesk',
)
);
$mail->SMTPAuth = true;
$mail->Username = 'sender#example.com';
$mail->Password = 'password';
$mail->setFrom('sender#example.com', 'Name Surname');
$mail->addAddress('recipient#domain.tld', 'Name Surname');
$mail->Subject = 'Email subject';
$mail->msgHTML('Email content with <strong>html</strong>');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
It assumes that local mail server is used and Default Plesk self signed certificate is used by mail server: Plesk > Tools & Settings > SSL/TLS Certificates > Certificate for securing mail

Symfony No Route To Host on edit, but works fine on findAll

I am using Symfony 3.0.4. I have the error
[2016-05-20 08:50:26] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occured in driver: SQLSTATE[HY000] [2002] No route to host" at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 103 {"exception":"[object] (Doctrine\\DBAL\\Exception\\ConnectionException(code: 0): An exception occured in driver: SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103, Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 2002): SQLSTATE[HY000] [2002] No route to host at /var/www/WebProduction/products.markettraders.com/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} []
[2016-05-20 08:50:26] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
This is strange because the indexAction is working perfectly, only the Edit Action is NOTWorking, on all of my edit routes. There have been no changes in the code to cause this to happen.
What have I inadvertantly changed in my MySQL configuration that allows Doctrine to find everything on the indexAction but then error out on the editAction?
EDIT
Forgive me.... The code is below. It works in my local environment. It does not work in prod. The error above comes from the prod.log.
In addition the indexAction controller works as well.
/**
* Displays a form to edit an existing AOD Technical Analysis page entity.
*
* #Route("/{id}/edit", name="aod_technical_analysis_edit")
* #Method({"GET", "POST"})
*/
public function editAction(Request $request, AodTechnicalAnalysis $aod_tech)
{
$deleteForm = $this->createDeleteForm($aod_tech);
$editForm = $this->createForm('AppBundle\Form\AodTechnicalAnalysisType', $aod_tech);
$editForm->remove('currencypair');
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($aod_tech);
$em->flush();
$session = $request->getSession();
$message = 'The change was succesfully saved for ' . $aod_tech->getCurrencypair();
$session->getFlashBag()->add('success', $message);
return $this->redirectToRoute('aod_technical_analysis_index');
}
return $this->render('aod_tech/edit.html.twig', array(
'aod_tech' => $aod_tech,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
Have you tried appending "app_dev.php" on your URL to get the debug web toolbar? I have found this to be more helpful compared to logs. You might need to edit the "web/app_dev.php" to add your browser's IP address.

Getting "Unexpected Token < " on my Google Maps api v3

I have a problem, I'm using this project to use of base on my project. I tryied to get the same result of the guys project, and used the same project to test in my SQL.
I done the "index.php" works, and when I click "Save Route" it send a mensage "Updated", so, when I open "loady.htm" it give that error : "SintaxError: Unexpected Token < "
I used the same code, but changed the local host on process.php and the account and password.
But this is the unique change.
What's wrong on load.htm ? Or its an error on teste.php, I cant load the waypoints in "loady.htm"
Links for test:
www.inventoresdegaragem.com/dbteste/index.htm
and
www.inventoresdegaragem.com/dbteste/loady.htm
Edit 2: This is my process.php
<? ob_start(); header('Cache-Control: no-store, no-cache, must-revalidate');
#$data = $_REQUEST['*******'];
$host = 'localhost';
$usuario = '******';
$banco = '******';
$senha = '******';
$db = mysql_connect($host, $usuario, $senha);
mysql_select_db($banco, $db);
if($_REQUEST['command']=='save')
{
$query = "update mapdir set value='$data'";
if(mysql_query($query))die('bien');
//die(mysql_error());
}
if($_REQUEST['command']=='fetch')
{
$query = "select value from mapdir";
if(!($res = mysql_query($query)));
$rs = mysql_fetch_array($res,1);
die($rs['value']);
}
?>
Your process.php cannot connect to your database.
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'http' (1) in /home/i/inventoresdegara/www/dbteste/process.php on line 10
It would appear that your current live version of process.php does not have localhost specified as the server. Note that it should be just a server name and should not include the protocol:
$host = 'localhost';
$host = 'www.mydomainnamehere.com';
(or whatever domain name you want to use) and not
$host = 'http://www.mydomainnamehere.com';
I believe the error is occurring because the database error message I've reproduced above is formatted as HTML and starts with <:
<br />
<b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Unknown MySQL server host 'http' (1) in <b>/home/i/inventoresdegara/www/dbteste/process.php</b> on line <b>10</b><br />
The html on your "after" page is not valid
looks like jax.responseText is empty.

'PDOException' with message 'SQLSTATE[HY000] [2002] zend framework

Any one plz tell me why i am getting this error ?? firstly my internet connection was good today its not good so i am getting this error.how can i fix this any idea plz??
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] A
connection attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has failed to
respond. ' in D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php:129
Stack trace: #0 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php(129):
PDO->__construct('mysql:host=192....', 'root', 'root', Array) #1 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Mysql.php(109):
Zend_Db_Adapter_Pdo_Abstract->_connect() #2 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Abstract.php(860):
Zend_Db_Adapter_Pdo_Mysql->_connect() #3 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Abstract.php(930):
Zend_Db_Adapter_Abstract->quote('testing', NULL) #4 D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Auth\Adapter\DbTable.php(449): Zen
in D:\SVN
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php on line
144
this is my config.ini
[general]
db.adapter = PDO_MYSQL
db.params.host = 192.168.0.233
db.params.username = root
db.params.password = my_password
db.params.dbname = "mydatabasename"
some code from my index.php
$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$DB = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($DB);
it seems that your code this portion is not working
[general]
db.adapter = PDO_MYSQL
db.params.host = 192.168.0.233
db.params.username = root
db.params.password = my_password
db.params.dbname = "mydatabasename"
either the IP is not correct if so go to cmd in windows and type ipconfig you will get your correct ip paste it here OR just simply write
db.params.host = localhost
if and only if you are using locally may be it works.
for the hostname/host try to use your credentials found in the Zend Server -> PHP Cloud tab -> Overview page -> User Parameters tab... then make the "host" part in the credentials like this:
[general]
db.adapter = PDO_MYSQL
db.params.host = CONTAINERNAME-db.my.phpcloud.com
db.params.username = ZEND_DB_USERNAME
db.params.password = ZEND_DB_USERNAME
db.params.dbname = ZEND_DB_DBNAME
Did you check your mysql database is up?
If you are sure it is, check that your adapters configuration is ok, maybe the host parameter is not properly configured.