Fedora Linux Support Community & Resources Center
  #1  
Old 25th February 2012, 09:40 AM
dysphorichermit Offline
Registered User
 
Join Date: May 2010
Location: United States
Posts: 35
linuxfedorafirefox
mysqli_connect with .my.cnf

Hello All.

Is there a way to use a password stored in a .my.cnf file with mysqli_connect instead of a username and password as seen the syntax example below? Thanks!

Code:
$dbc = mysqli_connect('localhost', 'user' 'password', 'databasename') or die('Error connecting to MySQL server.');
__________________
"I ask not for a lighter burden, but for broader shoulders."
Reply With Quote
  #2  
Old 26th February 2012, 09:40 AM
dysphorichermit Offline
Registered User
 
Join Date: May 2010
Location: United States
Posts: 35
linuxchrome
Re: mysqli_connect with .my.cnf

In retrospect I probably should have opened this in the software forum. .my.cnf won't work for securing the database connection in a php script but here's the best solution for securing said connection (which is what I really wanted):

set the include_path in /etc/php.ini:

Code:
vi /etc/php.ini
; UNIX: "/path1:/path2"
include_path = ".:/path/to/wherever/you/choose"
create a config.php file in the path you set for includes (example: vi /usr/local/php/config.php) and enter the following:

Code:
<?php
$dbc = mysqli_connect('localhost', 'your database username' 'your database password', 'your database name') or die('Error connecting to MySQL server.');
?>
then in the top of my php script that I need to connect to the db, I entered:
Code:
include('config.php');
the include function also works for securing the wp-config.php in wordpress. create another configuration.php file in the path you set for includes (example: vi /usr/local/php/wordpressconfig.php) and enter the following:

Code:
<?php
   define('DB_NAME', 'your database name');
   define('DB_USER', 'your database username');
   define('DB_PASSWORD', 'your database password');
   define('DB_HOST', 'localhost');
   define('DB_CHARSET', 'utf8');
   define('DB_COLLATE', '');
?>
edit your wp-config.php file and remove:

Code:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
and replace with:
Code:
include('wordpressconfig.php');
__________________
"I ask not for a lighter burden, but for broader shoulders."

Last edited by dysphorichermit; 26th February 2012 at 11:54 AM.
Reply With Quote
Reply

Tags
mycnf, mysqliconnect

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Current GMT-time: 09:56 (Friday, 31-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Shakiso Travel Photos on Instagram - Mugumu - Balugaon Travel Photos on Instagram