Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2011, 09:13 AM   PM User | #1
jobromedia
New to the CF scene

 
Join Date: Jul 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jobromedia is an unknown quantity at this point
Check MySQL version

I'm new here, and haven't got much experience using php yet. Still I think I can be of assistance since I'm currently struggling to get my own installer script running.

With that said requesting the mySQL version requires you to connect to the database. There is no other way around it.

Think of it this way. You want to get €100 from your bank account to get yourself some fancy computer hardware, but you got no proper legitimation to prove who you say you are. Without these credentials you cannot request anything from your account, it doesn't matter if you got the full account ID.

So the only valid way around the problem is:

1. Display a form to receive the database credentials.
2. Connect to the database with the credentials.
3. Display the current version of mySQL on the server.

Now think about it this way. Your end-user has some very imporant data stored inside his database that he doesn't want anyone to get hold of. It can be client's email adresses and then some. These database credentials are there to prevent unauthorized usage of your database. Same goes with the bank to prevent unauthorized usage of your money. Same goes with the keys to your flat. They're there to prevent any thieves from stealing your commodities.

No identification / credentials = access denied.

Here is a script to check the version of mysql from my script:
Code:
<?
	// Checking the version.
	include'conf.php';
	$qry = "SELECT VERSION()";
	$result = @mysql_query($qry);
	if (!$result) {
	   die("<font color='red'>Query error: " . mysql_error() . "</font>");
}
	$ver = @mysql_result($result, 0);
	print "<font color='green'>MySQL version: <b>$ver</b></font>";
	ob_end_flush();
?>
Below is the file conf.php
Code:
<?php
	// conf.php
	ob_start();
	$host="localhost"; // Host name
	$username="username"; // Mysql username
	$password="1234"; // Mysql password
	$db_name="database"; // Database name

	// Connect to server and select databse.
	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");
?>

Last edited by jobromedia; 07-26-2011 at 09:23 AM.. Reason: Added some scripts.
jobromedia is offline   Reply With Quote
Old 07-26-2011, 04:20 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
I moved this post here since it doesn't need to resurrect the thread it was posted it, but it may still be useful to someone.
Inigoesdr is offline   Reply With Quote
Old 07-27-2011, 05:53 AM   PM User | #3
jobromedia
New to the CF scene

 
Join Date: Jul 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jobromedia is an unknown quantity at this point
Sorry if I necro-posted. I'm quite good at that skill. With 10% sight on one eye I'm having a hard time locating the post date in most forums.

Anyways I'm glad you find this code useful enough to keep.
jobromedia is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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


All times are GMT +1. The time now is 01:38 PM.


Advertisement
Log in to turn off these ads.